Beispiel #1
0
 public bool SerializeToPRM(string prm_path)
 {
     using (st = System.IO.File.OpenWrite(prm_path))
     {
         WriteToPRM("DocType", DocType);
         WriteToPRM("Sender", Sender);
         WriteToPRM("Receiver", Receiver);
         //WriteToPRM("MsgDateTime", MsgDateTime.ToShortDateString());
         WriteToPRM("MsgDate", MsgDate);
         WriteToPRM("MsgTime", MsgTime);
         WriteToPRM("InvoiceType", InvoiceType);
         WriteToPRM("InvoiceNumber", InvoiceNumber);
         WriteToPRM("SupplierName", SupplierName);
         WriteToPRM("DiscountAmount", DiscountAmount);
         WriteToPRM("CompanyCode", CompanyCode.ToString());
         WriteToPRM("InvoiceDate", InvoiceDate.ToShortDateString());
         WriteToPRM("ExchangeRate", ExchangeRate.ToString());
         WriteToPRM("Currentcy", Currentcy);
         WriteToPRM("TaxInvoice", TaxInvoice);
         WriteToPRM("DocumentInvoiceType", DocumentInvoiceType);
         WriteToPRM("SupplierPrivateCompanyCode", SupplierPrivateCompanyCode);
         WriteToPRM("RetailerPrivateCompanyCode", RetailerPrivateCompanyCode);
         WriteToPRM("CurrencyDocumentSum", CurrencyDocumentSum.ToString());
         WriteToPRM("DocumentSum", DocumentSum.ToString());
         WriteToPRM("TaxSum", TaxSum.ToString());
         WriteToPRM("TaxSumNIS", TaxSumNIS.ToString());
         WriteToPRM("CurrencyRate", CurrencyRate.ToString());
         WriteToPRM("TaxRate", TaxRate);
         WriteToPRM("CompanyName", CompanyName);
         WriteToPRM("Address", Address);
         WriteToPRM("City", City);
         WriteToPRM("State", State);
         WriteToPRM("Country", Country);
         WriteToPRM("POB", POB);
         WriteToPRM("Zipcode", Zipcode);
         WriteToPRM("Bank", Bank);
         WriteToPRM("Account", Account);
         WriteToPRM("Details", Details);
         WriteToPRM("TotalLines", TotalLines.ToString());
         foreach (InvoiceLine line in Lines)
         {
             WriteToPRM(line);
         }
     }
     return(true);
 }
Beispiel #2
0
        public bool SerializeToXML(string path, string packingSlip, bool debug = true)
        {
            InvoiceXML inv_xml = new InvoiceXML();

            if (inv_xml.Envelope == null)
            {
                inv_xml.Envelope = new InvoiceXMLEnvelope();
            }
            if (inv_xml.Envelope.Header == null)
            {
                inv_xml.Envelope.Header = new InvoiceXMLEnvelopeHeader();
            }
            #region Note for auto-generated Invoice.cs
            // Note 1: For some reasons standalone attribute minOccurs brings problems - some fields are not serialized, so we have to remove them manually from XSD schema before class generation
            // Note 2: if Invoice.xsd was changed and Invoice.cs was re-geenrated using xsd.exe => the field below should be changed accordingly
            /// <remarks>
            /// This property was changed manually in order to control its output format
            /// </remarks>
            //  //[System.Xml.Serialization.XmlElementAttribute(DataType="time")]
            //public string MessageTime
            //{
            //    get
            //    {
            //        return System.String.Format("{0:HH:mm:ss}", this.messageTimeField);
            //    }
            //    set
            //    {
            //        this.messageTimeField = System.DateTime.Parse(value);
            //    }
            //}
            #endregion
            inv_xml.Envelope.MessageDate           = System.String.Format("{0:yyyy-MM-dd}", DateTime.Now);
            inv_xml.Envelope.MessageTime           = DateTime.Now.ToShortTimeString();
            inv_xml.Envelope.Sender                = Sender;
            inv_xml.Envelope.Receiver              = Receiver;
            inv_xml.Envelope.Header.Account        = Account;
            inv_xml.Envelope.Header.Address        = Address;
            inv_xml.Envelope.Header.Bank           = Bank;
            inv_xml.Envelope.Header.City           = City;
            inv_xml.Envelope.Header.CompanyCode    = CompanyCode.ToString().TrimEnd();
            inv_xml.Envelope.Header.CompanyName    = CompanyName;
            inv_xml.Envelope.Header.Country        = Country;
            inv_xml.Envelope.Header.Currency       = Currentcy;
            inv_xml.Envelope.Header.CurrencyDocSum = CurrencyDocumentSum.ToString();
//            inv_xml.Envelope.Header.Delivery = "";
            inv_xml.Envelope.Header.DiscountAmount = DiscountAmount;
            inv_xml.Envelope.Header.DocInvoiceType = InvoiceXMLEnvelopeHeaderDocInvoiceType.Original;//DocumentInvoiceType.ToString();
            inv_xml.Envelope.Header.DocSum         = DocumentSum;
            inv_xml.Envelope.Header.ExchangeRate   = ExchangeRate.ToString();
            inv_xml.Envelope.Header.InvoiceDate    = System.String.Format("{0:yyyy-MM-dd}", InvoiceDate);
            inv_xml.Envelope.Header.InvoiceNo      = InvoiceNumber;
            inv_xml.Envelope.Header.InvoiceType    = InvoiceType;
            inv_xml.Envelope.Header.LineSum        = LineSum;
            inv_xml.Envelope.Header.NumOfLines     = TotalLines.ToString();
//            inv_xml.Envelope.Header.PaymentTerms = "";
            inv_xml.Envelope.Header.POB       = POB;
            inv_xml.Envelope.Header.Reference = new InvoiceXMLEnvelopeHeaderReference[2 /*TotalLines*/];
            inv_xml.Envelope.Header.RetailerPrivateCompanyCode = RetailerPrivateCompanyCode;
            inv_xml.Envelope.Header.State        = State;
            inv_xml.Envelope.Header.SupplierName = SupplierName;
            inv_xml.Envelope.Header.SupplierPrivateCompanyCode = SupplierPrivateCompanyCode;
            inv_xml.Envelope.Header.TaxInvoice = InvoiceXMLEnvelopeHeaderTaxInvoice.TaxInvoice;

            string CurrencyRateStr = CurrencyRate.ToString();
            if (CurrencyRateStr.IndexOf(".") > 0)
            {
                if (CurrencyRateStr.IndexOf(".") + 5 <= CurrencyRateStr.Length)
                {
                    CurrencyRateStr = CurrencyRateStr.Substring(0, CurrencyRateStr.IndexOf(".") + 5);
                }
            }
            string TaxSumNISStr = TaxSumNIS.ToString();
            if (TaxSumNISStr.IndexOf(".") > 0)
            {
                if (TaxSumNISStr.IndexOf(".") + 3 <= TaxSumNISStr.Length)
                {
                    TaxSumNISStr = TaxSumNISStr.Substring(0, TaxSumNISStr.IndexOf(".") + 3);
                }
            }

            inv_xml.Envelope.Header.TaxRate      = TaxRate == null ? 0: System.Decimal.Parse(TaxRate);
            inv_xml.Envelope.Header.TaxSum       = TaxSum;
            inv_xml.Envelope.Header.TaxSumNIS    = TaxSumNISStr;
            inv_xml.Envelope.Header.CurrencyRate = CurrencyRateStr;
            inv_xml.Envelope.Header.Zipcode      = Zipcode;

            //Nasty hack
            inv_xml.Envelope.Header.SNAttachName = System.IO.Path.GetFileName(path).Replace(".xml", ".pdf");;
            inv_xml.Envelope.Details             = new InvoiceXMLEnvelopeLine[TotalLines];

            int counter = 0;
            foreach (InvoiceLine line in Lines)
            {
                //Console.WriteLine(String.Format("Preparing line #{0} from {1}:", counter, TotalLines));
                //Console.Out.Flush();

                if (counter == 0)
                {
                    InvoiceXMLEnvelopeHeaderReference Reference = new InvoiceXMLEnvelopeHeaderReference();
                    Reference.RefDate = System.String.Format("{0:yyyy-MM-dd}", line.ReferenceDate);
                    Reference.RefNo   = line.ReferenceNumber;
                    Reference.RefType = InvoiceXMLEnvelopeHeaderReferenceRefType.purchaseOrder;
                    inv_xml.Envelope.Header.Reference[counter] = Reference;
                    //22.4 added by liat form shipment reference
                    InvoiceXMLEnvelopeHeaderReference Reference2 = new InvoiceXMLEnvelopeHeaderReference();
                    Reference2.RefDate = System.String.Format("{0:yyyy-MM-dd}", line.ReferenceDate);
                    Reference2.RefNo   = packingSlip;
                    Reference2.RefType = InvoiceXMLEnvelopeHeaderReferenceRefType.shipment;
                    inv_xml.Envelope.Header.Reference[counter + 1] = Reference2;
                }
                //fix itemPriceBruto
                ///change by Pesya 23/07/2014 from 2 digit to 4 digit
                System.Diagnostics.EventLog.WriteEntry("DMS", "" + "before itemPriceBruto: " + line.ItemPriceBruto.ToString(), System.Diagnostics.EventLogEntryType.Information);
                string itemPriceBrutoStr = line.ItemPriceBruto.ToString();
                if (itemPriceBrutoStr.IndexOf(".") > 0)
                {
                    if (itemPriceBrutoStr.IndexOf(".") + 5 <= itemPriceBrutoStr.Length)
                    {
                        itemPriceBrutoStr = itemPriceBrutoStr.Substring(0, itemPriceBrutoStr.IndexOf(".") + 5);
                    }
                }
                System.Diagnostics.EventLog.WriteEntry("DMS", "" + "after itemPriceBrutoStr:  " + itemPriceBrutoStr, System.Diagnostics.EventLogEntryType.Information);
                ////////////////////////////
                //fix LineSum
                string LineSumStr = line.LineSum.ToString();
                if (LineSumStr.IndexOf(".") > 0)
                {
                    if (LineSumStr.IndexOf(".") + 3 <= LineSumStr.Length)
                    {
                        LineSumStr = LineSumStr.Substring(0, LineSumStr.IndexOf(".") + 3);
                    }
                }
                ////////////////////////////
                InvoiceXMLEnvelopeLine Detailes = new InvoiceXMLEnvelopeLine();
                Detailes.ItemBarcode     = line.ItemBarcode;
                Detailes.CustomerBarcode = line.CustomerBarcode;
                Detailes.ItemDescription = line.ItemDescription;
                Detailes.ItemPriceBruto  = itemPriceBrutoStr;
                Detailes.LineNo          = line.LineNo;
                Detailes.LineSum         = LineSumStr;
                Detailes.PartNumber      = line.PartNumber;
                Detailes.UnitsQty        = line.UnitQuantity.ToString();

                InvoiceXMLEnvelopeLineReference lRef = new InvoiceXMLEnvelopeLineReference();
                lRef.RefDate = System.String.Format("{0:yyyy-MM-dd}", line.ReferenceDate);
                lRef.RefNo   = line.ReferenceNumber;
                lRef.RefType = InvoiceXMLEnvelopeLineReferenceRefType.purchaseOrder;

                Detailes.Reference    = new InvoiceXMLEnvelopeLineReference[2];
                Detailes.Reference[0] = lRef;
                //added by Liat 22.4 reference for shipment
                InvoiceXMLEnvelopeLineReference lRef1 = new InvoiceXMLEnvelopeLineReference();
                lRef1.RefDate         = System.String.Format("{0:yyyy-MM-dd}", line.ReferenceDate);
                lRef1.RefType         = InvoiceXMLEnvelopeLineReferenceRefType.shipment;
                lRef1.RefNo           = packingSlip;
                Detailes.Reference[1] = lRef1;

                inv_xml.Envelope.Details[counter] = Detailes;

                //I don't understand how per item enteties are going up to the parent level, but that's what I was told...
                inv_xml.Envelope.Header.PaymentTerms = line.PaymentTerms;
                inv_xml.Envelope.Header.Delivery     = line.Delivery;
                counter++;
            }
            try
            {
                //using (StreamWriter output = new StreamWriter(new FileStream(path, FileMode.OpenOrCreate), Encoding.GetEncoding("windows-1255")))
                {
                    System.IO.FileStream fs = System.IO.File.Create(path);
                    XmlWriterSettings    xmlWriterSettings = new XmlWriterSettings
                    {
                        Indent             = true,
                        OmitXmlDeclaration = false,
                        Encoding           = Encoding.GetEncoding(1255)
                    };
                    System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(fs, xmlWriterSettings);
                    System.Xml.Serialization.XmlSerializerNamespaces nss = new System.Xml.Serialization.XmlSerializerNamespaces();
                    nss.Add("", "");
                    System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(inv_xml.GetType());
                    x.Serialize(writer, inv_xml, nss);
                    fs.Close();
                    if (debug)
                    {
                        x.Serialize(Console.Out, inv_xml);
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("DMS", "Exception in serialization method: " + e.ToString(), System.Diagnostics.EventLogEntryType.Error);
                if (debug)
                {
                    Console.WriteLine("Exception in serialization method: " + e.Message);
                }
                return(false);
            }
            return(true);
        }