示例#1
0
        /// <summary>
        /// - repeates document printed before.
        /// - Documents:Receipt,Invoice,Waybill,ReturnDocument,DiplomaticSale
        /// </summary>
        /// <param name="o"></param>
        public static void RepeatDocument(Object o)
        {
            DocumentFileHelper docHelper = null;

            if (o is DocumentFileHelper)
            {
                docHelper = o as DocumentFileHelper;
            }
            else
            {
                MenuLabel label = o as MenuLabel;
                docHelper = label.Value as DocumentFileHelper;
            }
            Hashtable data = new Hashtable();

            SalesDocument document = null;

            document            = docHelper.LoadDocument();
            document.FileOnDisk = docHelper.FileInfo;



            data.Add("Document", document);
            cr.State = RepeatConfirmed(data);
            //cr.Document.Id = docHelper.Id;
            cr.Document.Id = cr.Printer.CurrentDocumentId;
            docHelper.Remove(cr.Document);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        ///
        /// <returns></returns>
        public Decimal[] GetTaxGroupAdjustments()
        {
            if (taxGroupAdjustments == null)
            {
                SalesDocument document = (SalesDocument)(this.Target);
                taxGroupAdjustments = new Decimal[Department.NUM_TAXGROUPS];
                decimal productAdjustment, totalAdjustment = 0, maxAdjustment = 0;
                int     maxAdjustedProduct = 0;

                foreach (int dep in document.TaxGroupTotals.Keys)
                {
                    productAdjustment = Rounder.RoundDecimal(this.NetAmount * (document.TaxGroupTotals[dep] / this.adjustedTotal),
                                                             2,
                                                             true);
                    if (Math.Abs(productAdjustment) > Math.Abs(maxAdjustment))
                    {
                        maxAdjustment      = productAdjustment;
                        maxAdjustedProduct = dep;
                    }
                    taxGroupAdjustments[dep] += productAdjustment;
                    totalAdjustment          += productAdjustment;
                }
                taxGroupAdjustments[maxAdjustedProduct] += this.NetAmount - totalAdjustment;
            }
            return(taxGroupAdjustments);
        }
示例#3
0
 //:to do: function is called by also other classes, so it is static but it may not be here
 public static void AddMenuLabel(MenuList docTypes, String message, SalesDocument document)
 {
     if (cr.Printer.CanPrint(document))
     {
         docTypes.Add(new MenuLabel(message, document));
     }
 }
示例#4
0
        public override void Enter()
        {
            MenuLabel label = (MenuLabel)ie.Current;

            salesDoc = label.Value as SalesDocument;
            if (CashRegister.Document.IsEmpty)
            {
                if (salesDoc is Receipt)
                {
                    ProcessSelected(salesDoc);
                    CashRegister.State = Start.Instance();
                }
                else
                {
                    ProcessSelected(salesDoc);
                }
            }
            else
            {
                String  confirmationMessage = String.Format(PosMessage.CHANGE_DOCUMENT, salesDoc.Name);
                Confirm e = new Confirm(confirmationMessage,
                                        new StateInstance <Hashtable>(LDChangeConfirmed),
                                        new StateInstance(Start.Instance));
                e.Data["Document"] = salesDoc;
                CashRegister.State = ConfirmCashier.Instance(e);
            }
        }
示例#5
0
        private static IState OpenTables()
        {
            countToSellingState = 0;
            MenuList tableDocsMenu = new MenuList();
            String   label         = "";

            DisplayAdapter.Customer.ClearTableContent();
            List <DocumentFileHelper> tableDocuments = new List <DocumentFileHelper>(DocumentFileHelper.GetOpenTables());

            foreach (DocumentFileHelper helper in tableDocuments)
            {
                if (helper.FileInfo.Name.IndexOf("MASA10") > -1)
                {
                    label = "{0}:{1:D3}\t{2:dd/MM/yy}\n{3}\t{4}";
                    label = String.Format(label, PosMessage.TABLE_NUMBER, helper.Id, helper.CreationTime, PosMessage.TOTAL, 0);
                }
                else
                {
                    SalesDocument salesDocument = helper.LoadDocument();

                    label = "{0}:{1:D3}\t{2:dd/MM/yy}\n{3}\t{4}";
                    label = String.Format(label, PosMessage.TABLE_NUMBER, helper.Id, helper.CreationTime, PosMessage.TOTAL, salesDocument.TotalAmount);
                }

                tableDocsMenu.Add(new MenuLabel(label, helper));
            }

            return(List.Instance(tableDocsMenu, ShowTableOnDisp, Continue));
        }
示例#6
0
 public Receipt(SalesDocument doc)
     : base(doc)
 {
     if (TotalAmount > CashRegister.DataConnector.CurrentSettings.ReceiptLimit)
     {
         throw new ReceiptLimitExceededException();
     }
 }
示例#7
0
        public static String DocumentFormat(SalesDocument doc)
        {
            String format = "{0}{4} {1}\t{2:dd/MM/yy}\n{3:C}\t{2:H:mm}";

            return(String.Format(format, doc.Name.Substring(0, 3),
                                 doc.Id,
                                 doc.CreatedDate,
                                 new Number(doc.TotalAmount),
                                 (doc.Id > 999) ? ":" : " NO:"));
        }
示例#8
0
        private static IState FindDocument()
        {
            matchingDocument = cr.Document.ReadMainLogFile(numericDocId, numericZNo);
            if (matchingDocument == null || matchingDocument.Items.Count == 0)
            {
                return(AlertCashier.Instance(new Confirm(PosMessage.DOCUMENT_ID_NOT_FOUND,
                                                         new StateInstance(Continue))));
            }

            return(cr.State);
        }
示例#9
0
        private static void TransferToChoosenDoc(Object o)
        {
            MenuLabel     label    = o as MenuLabel;
            SalesDocument salesDoc = label.Value as SalesDocument;

            String  confirmationMessage = String.Format(PosMessage.CHANGE_DOCUMENT, salesDoc.Name);
            Confirm e = new Confirm(confirmationMessage,
                                    new StateInstance <Hashtable>(ListDocument.LDChangeConfirmed),
                                    new StateInstance(Start.Instance));

            e.Data["Document"] = salesDoc;
            CashRegister.State = ConfirmCashier.Instance(e);
        }
示例#10
0
        public static void ShowTableOnDisp(Object o)
        {
            DocumentFileHelper docHelper      = null;
            SalesDocument      document       = null;
            decimal            totalAdjAmount = 0.0m;

            if (o is DocumentFileHelper)
            {
                docHelper = o as DocumentFileHelper;
            }
            else
            {
                MenuLabel label = o as MenuLabel;
                docHelper = label.Value as DocumentFileHelper;
            }

            if (docHelper.FileInfo.Name.IndexOf("MASA10") > -1)
            {
                cr.State = AlertCashier.Instance(new Confirm("MASA BOÞ", OpenTables));
            }
            else if (countToSellingState == 1)
            {
                document            = docHelper.LoadDocument();
                document.FileOnDisk = docHelper.FileInfo;
                document.Id         = cr.Document.Id;
                String label = "{0}:{1:D3}\t{2}\n{3}?({4})";
                label = String.Format(label, PosMessage.TABLE_NUMBER, docHelper.Id, document.TotalAmount, PosMessage.CLOSE_TABLE, PosMessage.ENTER);
                Confirm e = new Confirm(label,
                                        new StateInstance <Hashtable>(RepeatConfirmed),
                                        new StateInstance(OpenTables));

                countToSellingState = 0;
                e.Data["Document"]  = document;
                cr.State            = ConfirmCashier.Instance(e);
                docHelper.Id        = cr.Document.Id;
                docHelper.Remove(cr.Document);
            }
            else
            {
                document = docHelper.LoadDocument();
                foreach (Adjustment adj in document.Adjustments)
                {
                    totalAdjAmount += adj.NetAmount;
                }

                DisplayAdapter.Customer.ShowTableContent(document, totalAdjAmount);
                countToSellingState++;
            }
        }
示例#11
0
        public override void Repeat()
        {
            DocumentFileHelper[] orders = DocumentFileHelper.GetOpenOrders();

            if (orders.Length > 0)
            {
                SalesDocument doc         = orders[0].LoadDocument();
                String        cashiername = doc.SalesPerson.Name;
                cashiername = cashiername.Substring(0, Math.Min(14, cashiername.Length));
                String label = doc.Name.Substring(0, 3) + " NO:{0:D4}\t{1:dd/MM/yy}\n{2}\t{1:HH:mm}";
                label = String.Format(label, doc.Id, doc.CreatedDate, cashiername);
                CommandMenu.RepeatDocument(new MenuLabel(label, orders[0]));
            }
            BackgroundWorker.ProcessTcpOrder();
        }
示例#12
0
 public void Remove(SalesDocument sDoc)
 {
     if (sDoc.Id == Id)
     {
         try
         {
             if (sDoc.Status != DocumentStatus.Voided || sDoc.Status != DocumentStatus.Cancelled)
             {
                 if (fileInfo.Name.IndexOf("MASA") > -1 && sDoc.Status == DocumentStatus.Active)
                 {
                     String nameToMove = String.Format("Sip{0:D3}{1}{2:MMddyyyy}.dat", fileInfo.Name.Substring(6, 3), sDoc.Id, DateTime.Now);
                     if (!Directory.Exists(PosConfiguration.ServerTablePath + "Success"))
                     {
                         Directory.CreateDirectory(PosConfiguration.ServerTablePath + "Success");
                     }
                     succesTableFullName = PosConfiguration.ServerTablePath + "Success/" + nameToMove;
                     File.Copy(fileInfo.FullName, succesTableFullName, true);
                     nameToMove = String.Format("{0}0{1}", fileInfo.Name.Substring(0, 5), fileInfo.Name.Substring(6));
                     fileInfo.Rename(PosConfiguration.ServerTablePath + nameToMove);
                     File.WriteAllText(PosConfiguration.ServerTablePath + nameToMove, String.Empty);
                 }
                 else if (fileInfo.Name.IndexOf("MASA") > -1 && sDoc.Status == DocumentStatus.Voided)
                 {
                     VoidTable(succesTableFullName);
                 }
                 else if (fileInfo.Name.IndexOf(".dat") > -1)
                 {
                     string name       = fileInfo.FullName.Substring(0, fileInfo.FullName.LastIndexOf('.'));
                     String nameToMove = String.Format("{0}{1:MMddyyyyHHmmss}.{2}", name, DateTime.Now, cr.Id.PadLeft(3, '0'));
                     fileInfo.Rename(nameToMove);
                 }
                 else
                 {
                     fileInfo.Delete();
                 }
             }
             else //there should be an error at document
             {
                 VoidOrder();
             }
         }
         catch { }
     }
 }
示例#13
0
        /// <summary>
        /// Add new fiscal item to document list.
        /// fiscal item: Void item or sales item.
        /// </summary>
        /// <param name="doc">
        /// Document list.
        /// </param>
        /// <param name="item">
        /// Item that will be added to document list.
        /// </param>
        public override void AddItem(SalesDocument doc, FiscalItem item)
        {
            Decimal newTotal = 0;

            if (item.TotalAmount >= 10000000)
            {
                throw new OverflowException(PosMessage.ITEM_TOTAL_AMOUNT_LIMIT_EXCEED_ERROR);
            }
            if (item.TotalAmount + doc.TotalAmount >= 100000000)
            {
                throw new OverflowException(PosMessage.DOCUMENT_TOTAL_AMOUNT_LIMIT_EXCEED_ERROR);
            }
            if (doc.ProductTotals.ContainsKey(item.Product))
            {
                newTotal = doc.ProductTotals[item.Product] + item.TotalAmount;
                if (newTotal < 0)
                {
                    throw new VoidException(PosMessage.VOID_AMOUNT_INVALID);
                }
                else if (newTotal == 0)
                {
                    doc.ProductTotals.Remove(item.Product);
                }
                else
                {
                    doc.ProductTotals[item.Product] += item.TotalAmount;
                }
            }
            else
            {
                if (item is VoidItem)
                {
                    throw new VoidException(PosMessage.CANNOT_VOID_NO_PROPER_SALE);
                }
                else
                {
                    doc.ProductTotals[item.Product] = item.TotalAmount;
                }
            }

            doc.Items.Add(item);
        }
示例#14
0
        public static IState RepeatDocument(string barcode)
        {
            SalesDocument doc = cr.Document.GetDocumentByBarcode(barcode);

            System.Threading.Thread.Sleep(250);
            if (doc != null && doc.Items.Count > 0)
            {
                String  label = DisplayAdapter.DocumentFormat(doc);
                Confirm e     = new Confirm(label,
                                            new StateInstance <Hashtable>(RepeatConfirmed),
                                            new StateInstance(Continue));
                e.Data["Document"] = doc;
                return(ConfirmCashier.Instance(e));
            }
            else
            {
                return(AlertCashier.Instance(new Confirm(PosMessage.BARCODE_NOTFOUND,
                                                         new StateInstance(Continue))));
            }
        }
示例#15
0
 public static IState LDChangeConfirmed(Hashtable data)
 {
     if (!((SalesDocument)data["Document"] is Receipt) && CashRegister.Document is Receipt)
     {
         CashRegister.Document.Transfer();
         CashRegister.Document.Void();
     }
     DisplayAdapter.Cashier.Show(PosMessage.TRANSFER_STARTED_PLEASE_WAIT);
     if (ProcessSelected != null)
     {
         ProcessSelected((SalesDocument)data["Document"]);
     }
     else
     {
         SalesDocument doc = (SalesDocument)data["Document"];
         CashRegister.ChangeDocumentType(doc);
     }
     if (salesDoc is Receipt)
     {
         return(Start.Instance());
     }
     return(CashRegister.State);
 }
示例#16
0
        static IState RepeatConfirmed(Hashtable data)
        {
            SalesDocument      document = null;
            DocumentFileHelper helper   = null;

            if (data["Document"] is DocumentFileHelper)
            {
                helper = ((DocumentFileHelper)data["Document"]);
                helper.LoadDocument();
            }
            else
            {
                document = (SalesDocument)data["Document"];
            }
            if (document.Status == DocumentStatus.Suspended)
            {
                document.Resume();
            }

            /*ICustomer customer = cr.Document.Customer;
             * cr.Document = (SalesDocument)document.Clone();
             *
             * if (customer != null)
             *  cr.Document.Customer = customer;
             */
            if (document.FileOnDisk != null)
            {
                if (document.FileOnDisk.Name.IndexOf("MASA") > -1)
                {
                    DisplayAdapter.Cashier.ClearTableContent();
                }
            }
            cr.ChangeDocumentType((SalesDocument)document.Clone());
            cr.Document.Id = cr.Printer.CurrentDocumentId;

            return(cr.State);
        }
示例#17
0
 public MealTicket(SalesDocument doc)
     : base(doc)
 {
 }
示例#18
0
        private void ProcessOrder(String orderLines, Socket client)
        {
            String [] lines = orderLines.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            byte []   buff  = new byte[1];

            SalesDocument doc = null;

            foreach (String orderLine in lines)
            {
                try
                {
                    switch (orderLine.Substring(8, 2))
                    {
                    case "01":    //FIS
                    case "02":    //FAT,IAD,IRS
                        switch (orderLine.Substring(11, 3))
                        {
                        case PosMessage.HR_CODE_INVOICE:
                            doc = new Invoice(); break;

                        case PosMessage.HR_CODE_RETURN:
                            doc = new ReturnDocument(); break;

                        case PosMessage.HR_CODE_WAYBILL:
                            doc = new Waybill(); break;

                        default:
                            doc = new Receipt();
                            break;
                        }
                        CashRegister.Printer.AdjustPrinter(doc);
                        CashRegister.Printer.PrintHeader(doc);
                        //doc.SalesPerson = cr.DataConnector.FindCashierById(line.Substring(23, 4));
                        break;

                    case "03":    //TAR
                        //1,00011,03,TAR,25/03/2009  ,00:21:26
                        break;

                    case "04":    //SAT
                    case "05":
                        FiscalItem si = new SalesItem();

                        String  pluNo     = orderLine.Substring(21, 6);
                        decimal amount    = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        decimal quantity  = Convert.ToDecimal(orderLine.Substring(15, 6)) / 1000m;
                        int     depID     = Convert.ToInt32(orderLine.Substring(28, 2));
                        String  name      = orderLine.Substring(41, 20).Trim().ToUpper();
                        decimal unitPrice = Math.Round(amount / quantity, 2);

                        IProduct prd = Data.Connector.Instance().CreateProduct(name + "DYNAMIC", Department.Departments[depID], unitPrice);

                        si.Quantity    = quantity;
                        si.Product     = prd;
                        si.TotalAmount = amount;
                        si.UnitPrice   = unitPrice;

                        if (orderLine.Contains("SAT"))
                        {
                            CashRegister.Printer.Print(si);
                            doc.Items.Add(si);
                        }
                        else
                        {
                            VoidItem vi = new VoidItem(si);
                            CashRegister.Printer.Print(vi);
                            doc.Items.Add(vi);
                        }
                        break;

                    case "06":    //IND,ART
                        AdjustmentType adjustmentType = AdjustmentType.Discount;
                        int            percentage     = 0;
                        bool           isPercent      = Parser.TryInt(orderLine.Substring(25, 2), out percentage);

                        IAdjustable target = doc.Items[doc.Items.Count - 1];
                        if (orderLine.Substring(15, 3) == "TOP")
                        {
                            target = doc;
                            CashRegister.Printer.PrintSubTotal(doc, true);
                        }

                        if (isPercent)
                        {
                            adjustmentType = AdjustmentType.PercentDiscount;
                        }

                        if (orderLine.Substring(11, 3) == "ART")
                        {
                            adjustmentType = isPercent ? AdjustmentType.PercentFee : AdjustmentType.Fee;
                        }

                        decimal adjAmount = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        if (isPercent)
                        {
                            adjAmount = (decimal)percentage;
                        }
                        Adjustment adj = new Adjustment(target, adjustmentType, adjAmount);
                        CashRegister.Printer.Print(adj);

                        target.Adjust(adj);
                        break;

                    case "08":
                        doc.TotalAmount = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        //DocumentStatus status = (DocumentStatus)Convert.ToInt16(orderLine.Substring(26, 1));
                        CashRegister.Printer.PrintTotals(doc, true);
                        break;

                    case "09":
                        decimal payment = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        switch (orderLine.Substring(11, 3))
                        {
                        case "NAK":
                            CashRegister.Printer.Pay(payment);
                            doc.Payments.Add(new CashPaymentInfo(payment));
                            break;

                        case "CEK":
                            String refNum = orderLine.Substring(15, 12).Trim();
                            CashRegister.Printer.Pay(payment, refNum);
                            doc.Payments.Add(new CheckPaymentInfo(payment, refNum));
                            break;

                        case "DVZ":
                            String  exCode = orderLine.Substring(15, 1);
                            decimal exAmnt = Convert.ToDecimal(orderLine.Substring(18, 9)) / 100m;
                            String  exName = orderLine.Substring(41, 20);
                            int     currId = int.Parse(orderLine.Substring(62, 2));

                            ICurrency currency = Data.Connector.Instance().GetCurrencies()[currId];

                            CashRegister.Printer.Pay(payment, currency);
                            doc.Payments.Add(new CurrencyPaymentInfo(currency, payment));
                            break;
                        }
                        break;

                    case "10":
                        decimal crdPayment   = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        int     installments = int.Parse(orderLine.Substring(15, 2));
                        int     crdId        = int.Parse(orderLine.Substring(25, 2));
                        String  crdName      = orderLine.Substring(41, 20);

                        ICredit crd = Data.Connector.Instance().GetCredits()[crdId];

                        CashRegister.Printer.Pay(crdPayment, crd, installments);
                        doc.Payments.Add(new CreditPaymentInfo(crd, crdPayment));
                        break;

                    case "11":
                        CashRegister.Printer.PrintFooter(doc, true);
                        Data.Connector.Instance().OnDocumentClosed(doc);
                        break;

                    case "22":
                        String remark = orderLine.Substring(15, orderLine.Length - 15).TrimEnd();
                        CashRegister.Printer.PrintRemark(remark);
                        break;

                    default: break;
                    }

                    buff[0] = ACK;
                    client.Send(buff);
                }
                catch
                {
                    if (doc != null)
                    {
                        CashRegister.Printer.Void();
                        Data.Connector.Instance().OnDocumentVoided(doc, (int)doc.Status);
                    }
                    buff[0] = NAK;
                    client.Send(buff);
                    break;
                }
            }

            if (buff[0] == ACK)
            {
                buff[0] = EOT;
                client.Send(buff);
            }
            orderState = OrderState.IDLE;
        }
示例#19
0
        private TCPMsgType ProcessOrder(String orderLines, Socket client)
        {
            String [] lines = orderLines.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            byte []   buff  = new byte[1];

            SalesDocument doc = null;

            TCPMsgType    retVal      = TCPMsgType.TCP_MSG_SALE;
            List <string> reportLines = new List <string>();

            CashRegister.Log.Info(orderLines);

            foreach (String orderLine in lines)
            {
                try
                {
                    switch (orderLine.Substring(8, 2))
                    {
                    case "01":    //FIS
                    case "02":    //FAT,IAD,IRS
                        CheckCashier();
                        switch (orderLine.Substring(11, 3))
                        {
                        case PosMessage.HR_CODE_INVOICE:
                            doc = new Invoice(); break;

                        case PosMessage.HR_CODE_RETURN:
                            doc = new ReturnDocument(); break;

                        case PosMessage.HR_CODE_WAYBILL:
                            doc = new Waybill(); break;

                        default:
                            doc = new Receipt();
                            break;
                        }

                        if (doc.DocumentTypeId >= 0)
                        {
                            doc.SlipSerialNo = orderLine.Substring(17, 10);
                            doc.TotalAmount  = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        }
                        CashRegister.Printer.AdjustPrinter(doc);
                        CashRegister.Printer.PrintHeader(doc);
                        //doc.SalesPerson = cr.DataConnector.FindCashierById(line.Substring(23, 4));
                        break;

                    case "03":    //TAR
                        //1,00011,03,TAR,25/03/2009  ,00:21:26
                        break;

                    case "04":    //SAT
                    case "05":
                        CheckCashier();
                        if (!(doc is Receipt))
                        {
                            break;
                        }
                        FiscalItem si = new SalesItem();

                        String   pluNo     = orderLine.Substring(21, 6);
                        decimal  amount    = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        decimal  quantity  = Convert.ToDecimal(orderLine.Substring(15, 6)) / 1000m;
                        int      depID     = Convert.ToInt32(orderLine.Substring(28, 2));
                        String   name      = orderLine.Substring(41, 20).Trim().ToUpper();
                        decimal  unitPrice = Math.Round(amount / quantity, 2);
                        String   unit      = orderLine.Substring(62, 4).Trim().ToUpper();
                        IProduct prd       = Data.Connector.Instance().CreateProduct(name + "DYNAMIC", Department.Departments[depID], unitPrice);

                        si.Quantity    = quantity;
                        si.Product     = prd;
                        si.TotalAmount = amount;
                        si.UnitPrice   = unitPrice;
                        si.Unit        = unit;
                        if (orderLine.Contains("SAT"))
                        {
                            CashRegister.Printer.Print(si);
                            doc.Items.Add(si);
                            doc.TotalAmount += si.TotalAmount;
                            if (doc.ProductTotals.ContainsKey(si.Product))
                            {
                                doc.ProductTotals[si.Product] += si.TotalAmount;
                            }
                            else
                            {
                                doc.ProductTotals.Add(si.Product, si.TotalAmount);
                            }
                        }
                        else
                        {
                            VoidItem vi = new VoidItem(si);
                            CashRegister.Printer.Print(vi);
                            doc.Items.Add(vi);
                            doc.TotalAmount -= vi.TotalAmount;
                            if (doc.ProductTotals.ContainsKey(vi.Product))
                            {
                                doc.ProductTotals[vi.Product] -= vi.TotalAmount;
                            }
                        }
                        break;

                    case "06":    //IND,ART
                        CheckCashier();
                        AdjustmentType adjustmentType = AdjustmentType.Discount;
                        int            percentage     = 0;
                        bool           isPercent      = Parser.TryInt(orderLine.Substring(25, 2), out percentage);

                        IAdjustable target = doc.Items[doc.Items.Count - 1];
                        if (orderLine.Substring(15, 3) == "TOP")
                        {
                            target = doc;
                            decimal total = CashRegister.Printer.PrinterSubTotal;
                            CashRegister.Printer.PrintSubTotal(doc, true);
                        }

                        if (isPercent)
                        {
                            adjustmentType = AdjustmentType.PercentDiscount;
                        }

                        if (orderLine.Substring(11, 3) == "ART")
                        {
                            adjustmentType = isPercent ? AdjustmentType.PercentFee : AdjustmentType.Fee;
                        }

                        decimal adjAmount = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        if (isPercent)
                        {
                            adjAmount = (decimal)percentage;
                        }
                        Adjustment adj = new Adjustment(target, adjustmentType, adjAmount);
                        CashRegister.Printer.Print(adj);

                        target.Adjust(adj);

                        if (adj.Target is SalesItem)
                        {
                            SalesItem adjTarget = (SalesItem)adj.Target;
                            if (doc.ProductTotals.ContainsKey(adjTarget.Product))
                            {
                                doc.ProductTotals[adjTarget.Product] += adj.NetAmount;
                            }
                            doc.TotalAmount += adj.NetAmount;
                        }
                        break;

                    case "08":
                        CheckCashier();
                        decimal totalAmount = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        //todo: compare total amaounts
                        //DocumentStatus status = (DocumentStatus)Convert.ToInt16(orderLine.Substring(26, 1));
                        decimal subTotal = CashRegister.Printer.PrinterSubTotal;
                        CashRegister.Printer.PrintTotals(doc, true);
                        break;

                    case "09":
                        CheckCashier();
                        decimal payment = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        switch (orderLine.Substring(11, 3))
                        {
                        case "NAK":
                            CashRegister.Printer.Pay(payment);
                            doc.Payments.Add(new CashPaymentInfo(payment));
                            break;

                        case "CEK":
                            String refNum = orderLine.Substring(15, 12).Trim();
                            CashRegister.Printer.Pay(payment, refNum);
                            doc.Payments.Add(new CheckPaymentInfo(payment, refNum));
                            break;

                        case "DVZ":
                            String  exCode = orderLine.Substring(15, 1);
                            decimal exAmnt = Convert.ToDecimal(orderLine.Substring(18, 9)) / 100m;
                            String  exName = orderLine.Substring(41, 20);
                            int     currId = int.Parse(orderLine.Substring(62, 2));

                            ICurrency currency = Data.Connector.Instance().GetCurrencies()[currId];

                            CashRegister.Printer.Pay(payment, currency);
                            doc.Payments.Add(new CurrencyPaymentInfo(currency, payment));
                            break;
                        }
                        break;

                    case "10":
                        CheckCashier();
                        decimal crdPayment   = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        int     installments = int.Parse(orderLine.Substring(15, 2));
                        int     crdId        = int.Parse(orderLine.Substring(25, 2));
                        String  crdName      = orderLine.Substring(41, 20);

                        ICredit crd = Data.Connector.Instance().GetCredits()[crdId];

                        CashRegister.Printer.Pay(crdPayment, crd, installments);
                        doc.Payments.Add(new CreditPaymentInfo(crd, crdPayment));
                        break;

                    case "11":
                        CheckCashier();
                        CashRegister.Printer.PrintFooter(doc);
                        Data.Connector.Instance().OnDocumentClosed(doc);
                        break;

                    case "22":
                        CheckCashier();
                        String remark = orderLine.Substring(15, orderLine.Length - 15).TrimEnd();
                        CashRegister.Printer.PrintRemark(remark);
                        break;

                    case "12":    //cash out
                        CheckCashier();
                        decimal cashOut = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        CashRegister.Printer.Withdraw(cashOut);
                        CashRegister.DataConnector.OnWithdrawal(cashOut);
                        retVal = TCPMsgType.TCP_MSG_CASH_OUT;
                        break;

                    case "13":    //cash in
                        CheckCashier();
                        decimal cashIn = Convert.ToDecimal(orderLine.Substring(30, 10)) / 100m;
                        CashRegister.Printer.Deposit(cashIn);
                        CashRegister.DataConnector.OnDeposit(cashIn);
                        retVal = TCPMsgType.TCP_MSG_CASH_IN;
                        break;

                    case "14":    //log in
                        if (orderLine.Substring(11, 3) != "LIN")
                        {
                            retVal = TCPMsgType.TCP_MSG_LOG_IN;
                            break;
                        }
                        String   cashierID   = orderLine.Substring(23, 4);
                        String   cashierPass = orderLine.Substring(28, 8);
                        String   cashierName = String.Format("KASIYER {0}", int.Parse(cashierID)); //orderLine.Substring(41, 20).Trim().ToUpper();
                        ICashier ch;
                        ch          = CashRegister.DataConnector.CreateCashier(cashierName + "FPU", cashierID);
                        ch.Password = cashierPass.Trim(new char[] { ' ', ',' });

                        /* ************ TODO: REMOVED ***************/
                        if (ch.Password == String.Empty)
                        {
                            switch (cashierID)
                            {
                            case "0001":
                                ch.Password = "******";
                                break;

                            case "0006":
                                ch.Password = "******";
                                break;

                            case "0009":
                                ch.Password = "******";
                                break;
                            }
                        }
                        /* ************ END TEMPRORARY CODE ***********/

                        try
                        {
                            CashRegister.Printer.SignInCashier(int.Parse(cashierID), ch.Password);
                            CashRegister.CurrentCashier = ch;
                        }
                        catch (CashierAlreadyAssignedException cEx)
                        {
                            if (cEx.CashierId == ch.Id)
                            {
                                CashRegister.CurrentCashier = ch;
                            }
                        }
                        catch
                        {
                        }
                        retVal = TCPMsgType.TCP_MSG_LOG_IN;
                        break;

                    case "15":    //log out
                        //String chID = orderLine.Substring(26, 4);
                        //String chName = orderLine.Substring(41, 20).Trim().ToUpper();
                        //ICashier chOut;
                        //chOut = CashRegister.DataConnector.CreateCashier(chName + "DYNAMIC", chID);
                        try
                        {
                            if (CashRegister.CurrentCashier != null)
                            {
                                CashRegister.Printer.SignOutCashier();
                            }
                            CashRegister.CurrentCashier = null;
                        }
                        catch
                        {
                        }
                        retVal = TCPMsgType.TCP_MSG_LOG_OUT;
                        break;

                    case "16":    //Daily report
                        CheckCashier();
                        switch (orderLine.Substring(11, 3))
                        {
                        case "ZRP":
                            CashRegister.Printer.PrintZReport();
                            break;

                        case "XRP":
                            CashRegister.Printer.PrintXReport(true);
                            break;
                        }
                        retVal = TCPMsgType.TCP_MSG_DAILY_REPORT;
                        break;

                    case "81":    //reports form
                        CheckCashier();
                        retVal = TCPMsgType.TCP_MSG_REPORT;
                        break;

                    case "82":    //paper cut
                        CheckCashier();
                        CashRegister.Printer.CutPaper();
                        retVal = TCPMsgType.TCP_MSG_CUT_PAPER;
                        break;

                    case "83":    //custom report
                        CheckCashier();
                        int nfDocType = 1;
                        switch (orderLine.Substring(11, 3))
                        {
                        case "ORP":        //stands for "OZEL RAPOR"
                            reportLines.Clear();
                            nfDocType = int.Parse(orderLine.Substring(15, 1));
                            break;

                        case "RSA":        //stands for "RAPOR SATIRI"
                            String repLine = orderLine.Substring(15).ToUpper();
                            reportLines.Add(repLine);
                            break;

                        case "RSO":        //stands for "RAPOR SONU"
                            if (nfDocType == 1)
                            {
                                CashRegister.Printer.PrintCustomReport(reportLines.ToArray());
                            }
                            else if (nfDocType == 2)
                            {
                                CashRegister.Printer.PrintCustomReceipt(reportLines.ToArray());
                            }
                            break;
                        }

                        retVal = TCPMsgType.TCP_MSG_CUSTOM_REPORT;
                        break;

                    case "84":    //date time setting
                        //1,00011,03,TAR,25/03/2009  ,00:21:26
                        int day  = int.Parse(orderLine.Substring(15, 2));
                        int mon  = int.Parse(orderLine.Substring(18, 2));
                        int year = int.Parse(orderLine.Substring(21, 4));

                        int hour = int.Parse(orderLine.Substring(28, 2));
                        int min  = int.Parse(orderLine.Substring(31, 2));
                        int sec  = 0;
                        try
                        {
                            sec = int.Parse(orderLine.Substring(34, 2));
                        }
                        catch { }

                        DateTime dtDate = new DateTime(year, mon, day, hour, min, sec);
                        CashRegister.Printer.Time = dtDate;
                        break;

                    case "85":    //Payment order
                        CheckCashier();
                        switch (orderLine.Substring(11, 3))
                        {
                        case "ABA":        //stands for "ADISYON BASLANGICI"
                            ISalesDocument invoice = new Invoice();
                            CashRegister.Printer.AdjustPrinter(invoice);
                            CashRegister.Printer.StartSlip(invoice);
                            break;

                        case "ASA":        //stands for "ADİSYON SATIRI"
                            String repLine = orderLine.Substring(15).ToUpper();
                            CashRegister.Printer.PrintSlipLine(repLine);
                            break;

                        case "ASO":        //stands for "ADİSYON SONU"
                            CashRegister.Printer.EndSlip(null);
                            break;
                        }
                        break;

                    case "86":    //Last document info
                        CheckCashier();
                        bool zReport = false;
                        switch (orderLine.Substring(11, 3))
                        {
                        case "SBB":        //stands for "Son Belge Bilgisi"
                            zReport = false;
                            break;

                        case "SZB":        //stands for "Son Z Bilgisi"
                            zReport = true;
                            break;
                        }

                        PrintedDocumentInfo lastDocInfo = CashRegister.Printer.GetLastDocumentInfo(zReport);
                        SendMessage(String.Format("{0:D4}{1:D4}{2:D4}{3:D2}{4:yyyyMMddHHmm}",
                                                  lastDocInfo.ZNo,
                                                  lastDocInfo.EjNo,
                                                  lastDocInfo.DocId,
                                                  (int)lastDocInfo.Type,
                                                  lastDocInfo.DocDateTime));
                        break;

                    case "99":
                        try
                        {
                            listener.Stop();
                            threadClient.Abort();
                        }catch {}
                        retVal = TCPMsgType.TCP_MSG_EXIT;
                        break;

                    default: break;
                    }

                    buff[0] = ACK;
                    client.Send(buff);
                }
                catch (Exception ex)
                {
                    string errMsg = new Error(ex).Message;
                    if (ex is PosException && ((PosException)ex).ErrorCode > 0)
                    {
                        errMsg = String.Format("{0:D4}", ((PosException)ex).ErrorCode);
                    }
                    if (doc != null)
                    {
                        try
                        {
                            CashRegister.Printer.Void();
                            Data.Connector.Instance().OnDocumentVoided(doc, 1);
                        }
                        catch
                        {
                        }
                    }


                    String data = String.Format("{0}{1}{2:D" + DIGITS_OF_LEN + "}{3}{4}",
                                                (char)NAK,
                                                (char)STX,
                                                errMsg.Length + 1,
                                                errMsg,
                                                (char)ETX);

                    buff = System.Text.Encoding.UTF8.GetBytes(data);
                    client.Send(buff);
                    break;
                }
            }

            if (buff[0] == ACK)
            {
                buff[0] = EOT;
                client.Send(buff);
            }

            return(retVal);
        }
示例#20
0
 /// <summary>
 /// Add fiscal item to document list.
 /// </summary>
 /// <param name="doc">
 /// Current document list.
 /// </param>
 /// <param name="item">
 /// Item that will be added.
 /// </param>
 public override void AddItem(SalesDocument doc, FiscalItem item)
 {
     doc.State = DocumentOpen.Instance();
     doc.State.AddItem(doc, item);
 }
示例#21
0
        //TODO Invalid file exception
        public SalesDocument LoadDocument()
        {
            int     docId       = 0;
            decimal checkTotals = 0;

            if (doc != null)
            {
                return(doc);
            }
            string context = fileInfo.ReadAllText();

            string[] lines = Str.Split(context, "\r\n", true);
            foreach (String line in lines)
            {
                try
                {
                    switch (line.Substring(8, 2))
                    {
                    case "01":    //FIS
                    case "02":    //FAT,IAD,IRS
                        switch (line.Substring(11, 3))
                        {
                        case PosMessage.HR_CODE_INVOICE:
                            doc = new Invoice();
                            break;

                        case PosMessage.HR_CODE_RETURN:
                            doc = new ReturnDocument();
                            break;

                        case PosMessage.HR_CODE_WAYBILL:
                            doc = new Waybill();
                            break;

                        default:
                            doc = new Receipt();
                            break;
                        }
                        docId           = int.Parse(line.Substring(28, 6));
                        doc.SalesPerson = cr.DataConnector.FindCashierById(line.Substring(23, 4));
                        break;

                    case "03":    //TAR
                        //1,00011,03,TAR,25/03/2009  ,00:21:26
                        DateTime date = DateTime.Now;
                        Parser.TryDate(line.Substring(15, 10).Replace('/', '.') + line.Substring(27, 9), out date);
                        break;

                    case "04":    //SAT
                        FiscalItem si = new SalesItem();
                        si.Quantity    = Convert.ToDecimal(line.Substring(15, 6)) / 1000;
                        si.Product     = cr.DataConnector.FindProductByLabel(line.Substring(21, 6));
                        si.TotalAmount = Convert.ToDecimal(line.Substring(30, 10)) / 100m;
                        checkTotals   += si.TotalAmount;
                        si.UnitPrice   = Math.Round(si.TotalAmount / si.Quantity, 2);

                        if (si.Quantity == 99)
                        {
                            if (tempSalesItem == null)
                            {
                                tempSalesItem         = new SalesItem();
                                tempSalesItem.Product = si.Product;
                            }

                            if (tempSalesItem.Quantity >= 99)
                            {
                                if (tempSalesItem.Product == si.Product)
                                {
                                    tempSalesItem.Quantity += 99;
                                }
                                else
                                {
                                    doc.AddItem(tempSalesItem, false);
                                    tempSalesItem = new SalesItem();
                                    tempSalesItem = (SalesItem)si;
                                }
                            }
                            else
                            {
                                tempSalesItem.Quantity += 99;
                                tempSalesItem.Quantity -= 1;     // constructor's default quantity.
                            }
                        }
                        else
                        {
                            if (tempSalesItem == null)
                            {
                                tempSalesItem = (SalesItem)si;
                            }

                            if (tempSalesItem.Quantity >= 99)
                            {
                                if (tempSalesItem.Product == si.Product)
                                {
                                    tempSalesItem.Quantity += si.Quantity;
                                    doc.AddItem(tempSalesItem, false);
                                    tempSalesItem = null;
                                }
                                else
                                {
                                    doc.AddItem(tempSalesItem, false);
                                    tempSalesItem = null;
                                    doc.AddItem(si, false);
                                }
                            }
                            else
                            {
                                doc.AddItem(si, false);
                                //tempSalesItem = null;
                            }
                        }
                        break;

                    case "05":    //IPT
                        if (tempSalesItem != null && tempSalesItem.Quantity >= 99)
                        {
                            doc.AddItem(tempSalesItem, false);
                        }

                        FiscalItem item = new SalesItem();
                        item.Quantity    = Convert.ToDecimal(line.Substring(15, 6)) / 1000;
                        item.Product     = cr.DataConnector.FindProductByLabel(line.Substring(21, 6));
                        item.TotalAmount = Convert.ToDecimal(line.Substring(30, 10)) / 100m;
                        checkTotals     -= item.TotalAmount;
                        FiscalItem vi = new VoidItem(item);
                        vi.UnitPrice = Math.Round(vi.TotalAmount / vi.Quantity, 2);
                        doc.AddItem(vi, false);

                        decimal vq = Math.Abs(vi.Quantity);
                        decimal va = Math.Abs(vi.TotalAmount);
                        for (int i = 0; i < doc.Items.Count; i++)
                        {
                            if (!(doc.Items[i] is SalesItem))
                            {
                                continue;
                            }

                            if ((doc.Items[i].Product.Id == vi.Product.Id) &&
                                (doc.Items[i].UnitPrice == vi.UnitPrice))
                            {
                                if (vq > doc.Items[i].Quantity)
                                {
                                    ((SalesItem)doc.Items[i]).VoidQuantity = doc.Items[i].Quantity;
                                    ((SalesItem)doc.Items[i]).VoidAmount   = doc.Items[i].TotalAmount;
                                    vq -= doc.Items[i].Quantity;
                                    va -= doc.Items[i].TotalAmount;
                                }
                                else
                                {
                                    if (((SalesItem)doc.Items[i]).VoidQuantity + vq >
                                        (((SalesItem)doc.Items[i]).Quantity - ((SalesItem)doc.Items[i]).VoidQuantity))
                                    {
                                        continue;
                                    }
                                    ((SalesItem)doc.Items[i]).VoidQuantity += vq;
                                    ((SalesItem)doc.Items[i]).VoidAmount   += va;
                                    break;
                                }
                            }
                        }
                        break;

                    case "06":    //IND,ART
                        AdjustmentType adjustmentType = AdjustmentType.Discount;
                        int            percentage     = 0;
                        bool           isPercent      = Parser.TryInt(line.Substring(25, 2), out percentage);

                        if (tempSalesItem.Quantity >= 99)
                        {
                            doc.AddItem(tempSalesItem, false);
                            tempSalesItem = null;
                        }
                        IAdjustable target = doc.LastItem;
                        if (line.Substring(15, 3) == "TOP")
                        {
                            target = doc;
                        }

                        if (isPercent)
                        {
                            adjustmentType = AdjustmentType.PercentDiscount;
                        }

                        if (line.Substring(11, 3) == "ART")
                        {
                            adjustmentType = isPercent ? AdjustmentType.PercentFee : AdjustmentType.Fee;
                        }

                        decimal amount = Convert.ToDecimal(line.Substring(30, 10)) / 100m;

                        if (adjustmentType == AdjustmentType.PercentFee || adjustmentType == AdjustmentType.Fee)
                        {
                            checkTotals += amount;
                        }
                        else
                        {
                            checkTotals -= amount;
                        }
                        if (isPercent)
                        {
                            amount = (decimal)percentage;
                        }
                        Adjustment adj = new Adjustment(target, adjustmentType, amount);
                        if (Math.Abs(adj.NetAmount) != Convert.ToDecimal(line.Substring(30, 10)) / 100m)
                        {
                            bool minus = adj.NetAmount < 0 ? true : false;
                            adj.NetAmount = Convert.ToDecimal(line.Substring(30, 10)) / 100m;
                            if (minus)
                            {
                                adj.NetAmount *= -1;
                            }
                        }
                        adj.AuthorizingCashierId = line.Substring(19, 4);

                        //Applying subtotal adjustments to retrieved documents
                        //could have side-effects. Only do item adjustments
                        // if (target is FiscalItem)
                        target.Adjust(adj);
                        break;

                    case "08":
                        if (tempSalesItem != null && tempSalesItem.Quantity >= 99)
                        {
                            doc.AddItem(tempSalesItem, false);
                        }
                        doc.TotalAmount = Convert.ToDecimal(line.Substring(30, 10)) / 100m;
                        int statusCode = 0;
                        if (Parser.TryInt(line.Substring(26, 1), out statusCode))
                        {
                            status = (DocumentStatus)statusCode;
                        }

                        break;

                    case "09":
                        amount = Convert.ToDecimal(line.Substring(30, 10)) / 100m;
                        switch (line.Substring(11, 3))
                        {
                        case "NAK":
                            doc.Payments.Add(new CashPaymentInfo(amount));
                            break;

                        case "CEK":
                            doc.Payments.Add(new CheckPaymentInfo(amount, line.Substring(15, 12)));
                            break;

                        case "DVZ":
                            int currId = 0;
                            if (Parser.TryInt(line.Substring(15, 1), out currId))
                            {
                                ICurrency c = cr.DataConnector.GetCurrencies()[(int)(currId + "")[0]];
                                doc.Payments.Add(new CurrencyPaymentInfo(c, amount));
                            }
                            break;
                        }
                        break;

                    case "10":    //KRD
                        amount = Convert.ToDecimal(line.Substring(30, 10)) / 100m;
                        int creditId    = 0;
                        int installment = 0;
                        if (Parser.TryInt(line.Substring(25, 2), out creditId))
                        {
                            ICredit c = cr.DataConnector.GetCredits()[creditId];
                            if (c != null)
                            {
                                Parser.TryInt(line.Substring(15, 2), out installment);
                                doc.Payments.Add(new CreditPaymentInfo(c, amount, installment));
                            }
                        }
                        break;

                    case "11":    //SON
                        decimal paidTotal = 0.00m;
                        foreach (PaymentInfo pi in doc.Payments)
                        {
                            paidTotal += pi.Amount;
                        }

                        //check if there are invalid values on file
                        if (checkTotals != doc.TotalAmount)
                        {
                            throw new Exception();
                        }

                        if (paidTotal < doc.TotalAmount)
                        {
                            throw new Exception();
                        }

                        if (paidTotal >= doc.TotalAmount)
                        {
                            status = DocumentStatus.Closed;
                        }
                        break;

                    case "29":    //NOT
                        doc.FootNote.Add(line.Substring(15, 12) + line.Substring(28, 12));
                        break;

                    case "36":    //SNO
                        string serialNo = line.Substring(15, 12) + line.Substring(28);
                        doc.LastItem.SerialNo = serialNo;
                        break;

                    case "37":    //PNO
                        string batchNo = line.Substring(15, 12) + line.Substring(28);
                        doc.LastItem.BatchNumber = batchNo;
                        break;

                    case "39":     //SKT
                        date = DateTime.Now;
                        Parser.TryDate(line.Substring(15, 10).Replace('/', '.') + line.Substring(27, 9), out date);
                        doc.LastItem.ExpiryDate = date;
                        break;

                    default: break;
                    }
                }
                catch (Exception err)
                {
                    cr.Log.Warning("siparis dosyasý hata : \n\t satýr: " + line);
                    VoidOrder();
                    throw err;
                }
            }
            if (id == 0)
            {
                id = docId;
            }
            doc.Id                    = id;
            doc.SalesPerson           = salesPerson;
            doc.ResumedFromDocumentId = resumedFromDocumentId;
            this.creationTime         = fileInfo.CreationTime;
            return(doc);
        }
示例#22
0
 public CarParkDocument(SalesDocument doc)
     : base(doc)
 {
 }
示例#23
0
 public Invoice(SalesDocument doc)
     : base(doc)
 {
 }
示例#24
0
 public CollectionInvoice(SalesDocument doc)
     : base(doc)
 {
 }
示例#25
0
        public PromotionDocument(SalesDocument doc, PaymentInfo paymentInfo, PromotionType promoType)
        {
            if (doc == null)
            {
                return;
            }

            virtualDoc          = (SalesDocument)doc.Clone();
            virtualDoc.Customer = doc.Customer;
            virtualDoc.Id       = doc.Id;

            if (paymentInfo != null)
            {
                virtualDoc.Payments.Add(paymentInfo);
            }


            if ((doc is ReturnDocument) &&
                (CashRegister.DataConnector.CurrentSettings.GetProgramOption(Setting.ApplyPromotionReturnDocument) == PosConfiguration.OFF))
            {
                return;
            }

            if (doc.CanEmpty)
            {
                return;
            }

            if ((paymentInfo is CreditPaymentInfo) &&
                ((CreditPaymentInfo)paymentInfo).Credit.IsTicket)
            {
                return;
            }

            //if (Math.Abs(doc.PromotedTotal) > 0)
            //{
            //    return;
            //}

            if (doc.Adjustments != null && doc.Adjustments.Length > 0)
            {
                //if (doc.Adjustments[doc.Adjustments.Length - 1].AuthorizingCashierId != CashRegister.PROMOTION_CASHIER_ID)
                {
                    virtualDoc.TotalAmount = doc.BalanceDue;
                    virtualDoc.BalanceDue  = doc.BalanceDue;
                }
                //else
                //{
                //    return;
                //}
            }

            Dictionary <int, int> matchIndex = new Dictionary <int, int>();
            int i = 0, j = 0;

            while (j < virtualDoc.Items.Count)
            {
                if (matchIndex.ContainsKey(j))
                {
                    matchIndex[j] = i;
                }
                else
                {
                    matchIndex.Add(j, i);
                }

                if (virtualDoc.Items[j].Quantity <= virtualDoc.Items[j].VoidQuantity || virtualDoc.Items[j].TotalAmount <= 0)
                {
                    virtualDoc.Items.RemoveAt(j);
                }
                else
                {
                    virtualDoc.Items[j].Quantity -= virtualDoc.Items[j].VoidQuantity;
                    j++;
                }
                i++;
            }

            String lines = CashRegister.DataConnector.FormatLines(virtualDoc);

            lines = lines + "\r\n";

            String[]      requestValue  = Str.Split(lines, "\r\n");
            String[]      responseValue = null;
            List <String> salesIndex    = new List <String>();
            int           temp = 0;

            i = 0;

            foreach (String requestLine in requestValue)
            {
                if (requestLine.Length < 10)
                {
                    continue;
                }
                if (Parser.TryInt(requestLine.Substring(8, 2), out temp) && (temp == 4 || temp == 5))
                {
                    salesIndex.Add(requestLine.Substring(3, 4));
                }
            }

            if (doc.Status != DocumentStatus.Paying)
            {
                isFirstPayment = true;
            }
            else
            {
                isFirstPayment = false;
            }

            try
            {
                if (CashRegister.PromoClient == null || !CashRegister.PromoClient.LogOn())
                {
                    return;
                }
                //Get Promotion list.
                if (promoType == PromotionType.Document)
                {
                    responseValue = CashRegister.PromoClient.DocumentRequest(requestValue, isFirstPayment);
                }
                else
                {
                    responseValue = CashRegister.PromoClient.ItemRequest(requestValue);
                }
            }
            catch (PromotionException pe)
            {
                String[] message = pe.Message.Split('\n');
                CashRegister.Log.Error(pe.Message);
                if (message[0].Length > 20 || (message.Length > 1 && message[1].Length > 20))
                {
                    throw new Exception("PROMOSYON UYGULAMA\nHATASI OLUÞTU".ToUpper());
                }

                throw new Exception(pe.Message.ToUpper());
            }
            catch
            {
                CashRegister.Log.Warning("Could not connect to promotion server at {0}", PosConfiguration.Get("PromoHostUri"));
                throw new Exception("PROMOSYON UYGULAMA\nHATASI OLUÞTU".ToUpper());
            }
            finally { isFirstPayment = false; }

            AdjustmentType promoAdjustType;
            bool           hasPromoKey = false;

            if (Math.Abs(doc.PromotedTotal) > 0)
            {
                foreach (string line in responseValue)
                {
                    if (line == null || line == String.Empty || line.StartsWith("0,"))
                    {
                        continue;
                    }
                    String[] value = line.Split(',');
                    try
                    {
                        switch (value[3])
                        {
                        case PosMessage.PRM:     // only point
                            int sign = doc is ReturnDocument ? -1 : 1;
                            virtualDoc.AddPoint(Int32.Parse(value[4]) * sign);
                            break;

                        case PosMessage.KOD:
                            String key = value[4].Trim();
                            hasPromoKey = true;
                            if (key != BackgroundWorker.GetAutoOrderKey())
                            {
                                virtualDoc = (SalesDocument)doc.Clone();
                                throw new InvalidSecurityKeyException();
                            }
                            break;
                        }
                    }
                    catch (InvalidSecurityKeyException iske)
                    {
                        throw iske;
                    }
                    catch (ProductPromotionLimitExeedException pplee)
                    {
                        throw pplee;
                    }
                    catch (InvalidPaymentException ipe)
                    {
                        throw ipe;
                    }
                    catch (Exception ex)
                    {
                        CashRegister.Log.Error(String.Format("Promosyon islemi hatali!:{0}", ex));
                        continue;
                    }
                }
            }
            else
            {
                foreach (string line in responseValue)
                {
                    if (line == null || line == String.Empty || line.StartsWith("0,"))
                    {
                        continue;
                    }
                    String[] value = line.Split(',');
                    try
                    {
                        switch (value[3])
                        {
                        case PosMessage.IND:
                            promoAdjustType = AdjustmentType.Discount;
                            goto Adjust;

                        case PosMessage.ART:
                            promoAdjustType = AdjustmentType.Fee;
                            goto Adjust;
Adjust:
                            Decimal adjustmentInput = 0;

                            if (Parser.TryDecimal(value[4].Substring(10), out adjustmentInput) &&
                                adjustmentInput > 0)
                            {
                                promoAdjustType = (promoAdjustType == AdjustmentType.Discount) ?
                                                  AdjustmentType.PercentDiscount :
                                                  AdjustmentType.PercentFee;
                            }
                            else if (!(Parser.TryDecimal(value[5], out adjustmentInput) &&
                                       adjustmentInput > 0))
                            {
                                continue;
                            }
                            else
                            {
                                adjustmentInput = Math.Round(adjustmentInput / 100m, 2);
                            }
                            if (value[4].Substring(0, 3) == PosMessage.SAT)
                            {
                                if (virtualDoc.RepeatedDocument)
                                {
                                    continue;
                                }
                                String salesId = value[4].Substring(4, 4);
                                i = salesIndex.IndexOf(salesId);
                                if (i < 0)
                                {
                                    continue;
                                }

                                SalesItem tempSales   = new SalesItem();
                                SalesItem currentItem = (SalesItem)virtualDoc.Items[i];
                                if (currentItem.VoidAmount > 0)
                                {
                                    //to calculate adjustment amount as remain product quantity
                                    tempSales.Product  = currentItem.Product;
                                    tempSales.Quantity = currentItem.Quantity;
                                }
                                else
                                {
                                    tempSales = currentItem;
                                }

                                Adjustment promoAdjustment = new Adjustment(tempSales,
                                                                            promoAdjustType,
                                                                            adjustmentInput,
                                                                            promoType == PromotionType.Document ? CashRegister.PROMOTION_CASHIER_ID :
                                                                            CashRegister.PROMOTION_ITEM_CASHIER_ID);
                                promoAdjustment.NetAmount = (Decimal.Parse(value[5]) / 100) * (promoAdjustment.NetAmount > 0 ? 1 : -1);
                                if (!virtualDoc.CanAdjust(promoAdjustment))
                                {
                                    CashRegister.Log.Error("Hatali promosyon uygulamasi: {0}", line);
                                    continue;
                                }

                                int indxOnSalesDoc = matchIndex[i];
                                if (doc.Items[indxOnSalesDoc].CanAdjust(promoAdjustment))
                                {
                                    promoAdjustment.Target = currentItem;
                                    promoAdjustment.Target.Adjust(promoAdjustment);
                                    promoAdjustment.Target = doc.Items[indxOnSalesDoc];
                                    itemAdjustments.Add(promoAdjustment);
                                }
                            }
                            else if (value[4].Substring(0, 3) == PosMessage.TOP)
                            {
                                Adjustment promoAdjustment = new Adjustment(virtualDoc, promoAdjustType,
                                                                            adjustmentInput,
                                                                            CashRegister.PROMOTION_CASHIER_ID);
                                if (!virtualDoc.CanAdjust(promoAdjustment))
                                {
                                    CashRegister.Log.Error("Hatali promosyon uygulamasi: {0}", line);
                                    continue;
                                }
                                virtualDoc.Adjust(promoAdjustment);
                                //this.Adjust(promoAdjustment);
                            }
                            break;

                        case PosMessage.PRM:
                            int sign = doc is ReturnDocument ? -1 : 1;
                            virtualDoc.AddPoint(Int32.Parse(value[4]) * sign);
                            break;

                        case PosMessage.NOT:
                            String fnValue = line.Substring(line.IndexOf(PosMessage.NOT) + PosMessage.NOT.Length + 1).Trim();
                            virtualDoc.FootNote.Add(fnValue);
                            break;

                        case PosMessage.MSG:
                            String msg = value[4].Trim();
                            if (msg.Length > 32)
                            {
                                msg = msg.Substring(0, 32);
                            }
                            if (msg.Length > 0)
                            {
                                virtualDoc.Remark.Add(msg);
                            }
                            break;

                        case "OZL":
                            String warn = value[4].Trim();
                            virtualDoc.FootNote.Add(warn);
                            if (warn.Length > 40)
                            {
                                warn = warn.Substring(0, 40);
                            }
                            warn = warn.Insert(20, "\n");
                            DisplayAdapter.Cashier.Show(warn);
                            System.Threading.Thread.Sleep(500);
                            break;

                        case PosMessage.KOD:
                            String key = value[4].Trim();
                            hasPromoKey = true;
                            if (key != BackgroundWorker.GetAutoOrderKey())
                            {
                                virtualDoc = (SalesDocument)doc.Clone();
                                throw new InvalidSecurityKeyException();
                            }
                            break;

                        case PosMessage.LMT:
                            if (line.Substring(15, 3) == "SAT")
                            {
                                virtualDoc = (SalesDocument)doc.Clone();
                                throw new ProductPromotionLimitExeedException();
                            }
                            else if (line.Substring(15, 3) == "TOP")
                            {
                                virtualDoc = (SalesDocument)doc.Clone();
                                throw new InvalidPaymentException(PosMessage.PAYMENT_INVALID);
                            }
                            break;

                        case PosMessage.HAR:
                            logLines.Add(line.Substring(line.IndexOf(PosMessage.HAR) + PosMessage.HAR.Length + 1));
                            break;
                        }
                    }
                    catch (InvalidSecurityKeyException iske)
                    {
                        throw iske;
                    }
                    catch (ProductPromotionLimitExeedException pplee)
                    {
                        throw pplee;
                    }
                    catch (InvalidPaymentException ipe)
                    {
                        throw ipe;
                    }
                    catch (Exception ex)
                    {
                        CashRegister.Log.Error(String.Format("Promosyon islemi hatali!:{0}", ex));
                        continue;
                    }
                }
            }

            if (!hasPromoKey && responseValue.Length > 0)
            {
                virtualDoc = (SalesDocument)doc.Clone();
                throw new Exception("PROMOSYON LÝSANSI\nEKSÝK".ToUpper());
            }
        }
示例#26
0
 /// <summary>
 /// After payment is started,document must be closed to sell or void new item.
 /// If cashier try to sell or void item,it does not permitted and alerted by the system to close sales.
 /// </summary>
 /// <param name="doc">
 /// Not used in this state.
 /// </param>
 /// <param name="item">
 /// Not used in this state.
 /// </param>
 /// <exception cref="SaleClosedException">
 /// Alerts cashier to close sales document in order to add new sales item.
 /// </exception>
 public override void AddItem(SalesDocument doc, FiscalItem item)
 {
     throw new SaleClosedException(String.Format("{0}\n{1}", PosMessage.RECEIVE_PAYMENT,
                                                 PosMessage.PROMPT_FINALIZE_SALE));
 }
示例#27
0
 public ReturnDocument(SalesDocument doc)
     : base(doc)
 {
 }
示例#28
0
 public void Remove(SalesDocument sDoc)
 {
 }
示例#29
0
 public Waybill(SalesDocument doc)
     : base(doc)
 {
 }
示例#30
0
 abstract public void Show(SalesDocument sd);