Пример #1
0
        internal void Print_Receipt_ESC_POS(InvoiceData xInvoiceData,
                                            string FursD_BussinesPremiseID,
                                            string ElectronicDevice_ID,
                                            int BaseCurrency_DecimalPlaces,
                                            GlobalData.ePaymentType PaymentType, string sPaymentMethod, string sAmountReceived, string sToReturn, DateTime_v issue_time)
        {
            //ReceiptPrinter.Print(ep.InitializePrinter());
            long journal_docinvoice_id = -1;

            try
            {

                if (InitializePrinter())
                {

                }
                if (PrintInBuffer)
                {
                    Clear();
                }

                if (xInvoiceData.MyOrganisation.Logo_Data != null)
                {
                    this.wr_BitmapByteArray570x570imagesize(xInvoiceData.MyOrganisation.Logo_Data);
                }

                wr_SelectAnInternationalCharacterSet(Printer.eCharacterSet.Slovenia_Croatia);
                wr_Paragraph(xInvoiceData.MyOrganisation.Name);
                wr_Paragraph(xInvoiceData.MyOrganisation.Address.StreetName + " " + xInvoiceData.MyOrganisation.Address.HouseNumber);
                wr_Paragraph(xInvoiceData.MyOrganisation.Address.ZIP + " " + xInvoiceData.MyOrganisation.Address.City);
                if (xInvoiceData.MyOrganisation.HomePage != null)
                {
                    if (xInvoiceData.MyOrganisation.HomePage.Length > 0)
                    {
                        wr_String("Domača stran:");
                        wr_SelectAnInternationalCharacterSet(Printer.eCharacterSet.USA);
                        wr_String(xInvoiceData.MyOrganisation.HomePage);
                        wr_SelectAnInternationalCharacterSet(Printer.eCharacterSet.Slovenia_Croatia);
                        wr_NewLine();
                        ;
                    }
                }
                if (xInvoiceData.MyOrganisation.Email != null)
                {
                    if (xInvoiceData.MyOrganisation.Email.Length > 0)
                    {
                        wr_String("EPOŠTA:");
                        wr_SelectAnInternationalCharacterSet(Printer.eCharacterSet.USA);
                        wr_String(xInvoiceData.MyOrganisation.Email);
                        wr_SelectAnInternationalCharacterSet(Printer.eCharacterSet.Slovenia_Croatia);
                    }
                }
                wr_NewLine();
                wr_Paragraph("Davčna Številka:" + xInvoiceData.MyOrganisation.Tax_ID);
                wr_NewLine(2);
                //buffer = buffer + "\x1b\x1d\x61\x0";             //Left Alignment - Refer to Pg. 3-29
                wr_SetHorizontalTabPositions(new byte[] { 2, 0x10, 0x22 });
                wr_Paragraph("Številka računa: " + xInvoiceData.FinancialYear.ToString() + "/" + xInvoiceData.NumberInFinancialYear.ToString());
                wr_Paragraph("Datum:" + xInvoiceData.IssueDate_v.v.Day.ToString() + "." + xInvoiceData.IssueDate_v.v.Month.ToString() + "." + xInvoiceData.IssueDate_v.v.Year.ToString() + "\x9" + " Čas:" + xInvoiceData.IssueDate_v.v.Hour.ToString() + ":" + xInvoiceData.IssueDate_v.v.Minute.ToString());      //Moving Horizontal Tab - Pg. 3-26
                wr_LineDelimeter();
                wr_BoldOn();

                wr_Paragraph("PRODANO:");
                wr_NewLine();
                wr_BoldOff();

                //Select Emphasized Printing - Pg. 3-14;                    //Cancel Emphasized Printing - Pg. 3-14

                taxSum = null;
                taxSum = new StaticLib.TaxSum();

                foreach (ItemSold itmsold in xInvoiceData.ItemsSold)
                {
                    wr_Paragraph(itmsold.Item_Name);
                    wr_String("Cena za enoto" + HT + itmsold.RetailPricePerUnit.ToString() + " EUR\n");
                    decimal TotalDiscount = StaticLib.Func.TotalDiscount(itmsold.Discount, itmsold.ExtraDiscount, BaseCurrency_DecimalPlaces);
                    decimal TotalDiscountPercent = TotalDiscount * 100;
                    if (TotalDiscountPercent > 0)
                    {
                        wr_String("Popust:" + TotalDiscountPercent.ToString() + " %\n");
                    }
                    wr_String("Količina:" + HT + itmsold.dQuantity.ToString() + "\n");
                    if (TotalDiscountPercent > 0)
                    {
                        wr_String("Cena s popustom:" + HT + HT + itmsold.PriceWithTax.ToString() + " EUR\n");
                    }
                    else
                    {
                        wr_String("Cena " + HT + HT + HT + itmsold.PriceWithTax.ToString() + " EUR\n");
                    }
                    wr_String(itmsold.TaxationName + HT + HT + itmsold.TaxPrice.ToString() + " EUR\n");
                    wr_NewLine();
                }

                //foreach (DataRow dr in xInvoiceData.dt_ShopB_Items.Rows)
                //{
                //    object o_SimpleItem_name = dr["Name"];
                //    string SimpleItem_name = null;
                //    if (o_SimpleItem_name.GetType() == typeof(string))
                //    {
                //        SimpleItem_name = (string)o_SimpleItem_name;
                //    }

                //    decimal RetailSimpleItemPrice = 0;
                //    object o_RetailSimpleItemPrice = dr["RetailSimpleItemPrice"];
                //    if (o_RetailSimpleItemPrice.GetType() == typeof(decimal))
                //    {
                //        RetailSimpleItemPrice = (decimal)o_RetailSimpleItemPrice;
                //    }

                //    decimal RetailSimpleItemPriceWithDiscount = 0;
                //    object o_RetailSimpleItemPriceWithDiscount = dr["RetailSimpleItemPriceWithDiscount"];
                //    if (o_RetailSimpleItemPriceWithDiscount.GetType() == typeof(decimal))
                //    {
                //        RetailSimpleItemPriceWithDiscount = (decimal)o_RetailSimpleItemPriceWithDiscount;
                //    }

                //    string TaxationName = "Davek ???";
                //    object oTaxationName = dr["Atom_Taxation_Name"];
                //    if (oTaxationName is string)
                //    {
                //        TaxationName = (string)oTaxationName;
                //    }

                //    decimal TaxPrice = -1;
                //    object oTaxPrice = dr["TaxPrice"];
                //    if (oTaxPrice is decimal)
                //    {
                //        TaxPrice = (decimal)oTaxPrice;
                //        taxSum.Add(TaxPrice, 0, (string)dr["Atom_Taxation_Name"], (decimal)dr["Atom_Taxation_Rate"]);
                //    }

                //    int iQuantity = -1;
                //    object oQuantity = dr["iQuantity"];
                //    if (oQuantity is int)
                //    {
                //        iQuantity = (int)oQuantity;
                //    }

                //    decimal Discount = 0;
                //    object oDiscount = dr["Discount"];
                //    if (oDiscount is decimal)
                //    {
                //        Discount = (decimal)oDiscount;
                //    }

                //    decimal ExtraDiscount = 0;
                //    object oExtraDiscount = dr["ExtraDiscount"];
                //    if (oExtraDiscount is decimal)
                //    {
                //        ExtraDiscount = (decimal)oExtraDiscount;
                //    }

                //    Printer.wr_Paragraph(SimpleItem_name);
                //    Printer.wr_String("Cena za enoto" + HT + RetailSimpleItemPrice.ToString() + " EUR\n");
                //    decimal TotalDiscount = StaticLib.Func.TotalDiscount(Discount, ExtraDiscount, Program.Get_BaseCurrency_DecimalPlaces());
                //    decimal TotalDiscountPercent = TotalDiscount * 100;
                //    if (TotalDiscountPercent > 0)
                //    {
                //        Printer.wr_String("Popust:" + TotalDiscountPercent.ToString() + " %\n");
                //    }
                //    Printer.wr_String("Količina:" + HT + iQuantity.ToString() + "\n");
                //    if (TotalDiscountPercent > 0)
                //    {
                //        Printer.wr_String("Cena s popustom:" + HT + HT + RetailSimpleItemPriceWithDiscount.ToString() + " EUR\n");
                //    }
                //    else
                //    {
                //        Printer.wr_String("Cena " + HT + HT + HT + RetailSimpleItemPriceWithDiscount.ToString() + " EUR\n");
                //    }
                //    Printer.wr_String(TaxationName + HT + HT + TaxPrice.ToString() + " EUR\n");
                //    Printer.wr_NewLine();

                //}

                ////DocInvoice_ShopC_Item.ID AS DocInvoice_ShopC_Item_ID,
                ////DocInvoice_ShopC_Item.DocInvoice_ID,
                ////DocInvoice.Atom_myOrganisation_Person_ID,
                ////DocInvoice_ShopC_Item.Stock_ID,
                ////DocInvoice_ShopC_Item.Atom_Price_Item_ID,
                ////Atom_Item.ID as Atom_Item_ID,
                ////itm.ID as Item_ID,
                ////Atom_Price_Item.RetailPricePerUnit,
                ////Atom_Price_Item.Discount,
                ////DocInvoice_ShopC_Item.RetailPriceWithDiscount,
                ////DocInvoice_ShopC_Item.TaxPrice,
                ////DocInvoice_ShopC_Item.ExtraDiscount,
                ////DocInvoice_ShopC_Item.dQuantity,
                ////DocInvoice_ShopC_Item.ExpiryDate,
                ////Atom_Item.UniqueName AS Atom_Item_UniqueName,
                ////Atom_Item_Name.Name AS Atom_Item_Name_Name,
                ////Atom_Item_barcode.barcode AS Atom_Item_barcode_barcode,
                ////Atom_Taxation.Name AS Atom_Taxation_Name,
                ////Atom_Taxation.Rate AS Atom_Taxation_Rate,
                ////Atom_Item_Description.Description AS Atom_Item_Description_Description,
                ////Atom_Item.Atom_Warranty_ID,
                ////Atom_Warranty.WarrantyDurationType AS Atom_Warranty_WarrantyDurationType,
                ////Atom_Warranty.WarrantyDuration AS Atom_Warranty_WarrantyDuration,
                ////Atom_Warranty.WarrantyConditions AS Atom_Warranty_WarrantyConditions,
                ////Atom_Item.Atom_Expiry_ID,
                ////Atom_Expiry.ExpectedShelfLifeInDays AS Atom_Expiry_ExpectedShelfLifeInDays,
                ////Atom_Expiry.SaleBeforeExpiryDateInDays AS Atom_Expiry_SaleBeforeExpiryDateInDays,
                ////Atom_Expiry.DiscardBeforeExpiryDateInDays AS Atom_Expiry_DiscardBeforeExpiryDateInDays,
                ////Atom_Expiry.ExpiryDescription AS Atom_Expiry_ExpiryDescription,
                ////puitms.Item_ID AS Stock_Item_ID,
                ////Stock.ImportTime AS Stock_ImportTime,
                ////Stock.dQuantity AS Stock_dQuantity,
                ////Stock.ExpiryDate AS Stock_ExpiryDate,
                ////Atom_Unit.Name AS Atom_Unit_Name,
                ////Atom_Unit.Symbol AS Atom_Unit_Symbol,
                ////Atom_Unit.DecimalPlaces AS Atom_Unit_DecimalPlaces,
                ////Atom_Unit.Description AS Atom_Unit_Description,
                ////Atom_Unit.StorageOption AS Atom_Unit_StorageOption,
                ////Atom_PriceList.Name AS Atom_PriceList_Name,
                ////Atom_Currency.Name AS Atom_Currency_Name,
                ////Atom_Currency.Abbreviation AS Atom_Currency_Abbreviation,
                ////Atom_Currency.Symbol AS Atom_Currency_Symbol,
                ////Atom_Currency.DecimalPlaces AS Atom_Currency_DecimalPlaces
                //Printer.wr_NewLine();

                //foreach (DocInvoice_ShopC_Item_Data appisd in xInvoiceData.m_ShopABC.m_CurrentInvoice.m_Basket.DocInvoice_ShopC_Item_Data_LIST)
                //{
                //    string Item_UniqueName = appisd.Atom_Item_UniqueName.v;

                //    decimal RetailPricePerUnit = appisd.RetailPricePerUnit.v;

                //    decimal RetailItemPriceWithDiscount = appisd.RetailPriceWithDiscount.v;

                //    Printer.wr_String(Item_UniqueName + "\n");

                //    decimal dQuantity = appisd.dQuantity_FromStock + appisd.dQuantity_FromFactory;

                //    string Atom_Unit_Name = appisd.Atom_Unit_Name.v;

                //    Printer.wr_String("Cena za 1 " + Atom_Unit_Name + " = " + RetailPricePerUnit.ToString() + " EUR\n");

                //    decimal Discount = appisd.Discount.v;

                //    decimal ExtraDiscount = appisd.ExtraDiscount.v;

                //    decimal TotalDiscount = StaticLib.Func.TotalDiscount(Discount, ExtraDiscount, Program.Get_BaseCurrency_DecimalPlaces());
                //    decimal TotalDiscountPercent = TotalDiscount * 100;
                //    if (TotalDiscountPercent > 0)
                //    {
                //        Printer.wr_String("Popust:" + TotalDiscountPercent.ToString() + " %\n");
                //    }
                //    Printer.wr_String("Količina:" + HT + dQuantity.ToString() + " " + Atom_Unit_Name + "\n");

                //    decimal Atom_Taxation_Rate = appisd.Atom_Taxation_Rate.v;

                //    decimal RetailItemsPriceWithDiscount = 0;
                //    decimal ItemsTaxPrice = 0;
                //    decimal ItemsNetPrice = 0;

                //    int decimal_places = appisd.Atom_Currency_DecimalPlaces.v;

                //    StaticLib.Func.CalculatePrice(RetailPricePerUnit, dQuantity, Discount, ExtraDiscount, Atom_Taxation_Rate, ref RetailItemsPriceWithDiscount, ref ItemsTaxPrice, ref ItemsNetPrice, decimal_places);

                //    if (TotalDiscountPercent > 0)
                //    {
                //        Printer.wr_String("Cena s popustom:" + HT + HT + RetailItemsPriceWithDiscount.ToString() + " EUR\n");
                //    }
                //    else
                //    {
                //        Printer.wr_String("Cena " + HT + HT + HT + RetailItemsPriceWithDiscount.ToString() + " EUR\n");
                //    }

                //    string TaxationName = appisd.Atom_Taxation_Name.v;

                //    decimal TaxPrice = appisd.TaxPrice.v;

                //    taxSum.Add(ItemsTaxPrice, 0, TaxationName, Atom_Taxation_Rate);

                //    Printer.wr_String(TaxationName + HT + HT + ItemsTaxPrice.ToString() + " EUR\n");
                //    Printer.wr_NewLine();

                //}
                wr_LineDelimeter();

                foreach (StaticLib.Tax tax in taxSum.TaxList)
                {
                    wr_String(tax.Name + HT + HT + "" + tax.TaxAmount.ToString() + " EUR\n");
                }

                wr_String("Brez davka " + HT + HT + "" + xInvoiceData.NetSum.ToString() + " EUR\n");
                //buffer += "\x1B" + "G" + "\xFF";
                wr_String("Skupaj " + HT + HT + xInvoiceData.GrossSum.ToString() + " EUR\n");
                //buffer += "\x1B" + "G" + "\x00\n";
                if (PaymentType != GlobalData.ePaymentType.NONE)
                {
                    wr_String("Način plačila:" + sPaymentMethod + "\n");
                    if (PaymentType == GlobalData.ePaymentType.CASH)
                    {
                        wr_String("  Prejeto: " + sAmountReceived + " EUR\n");
                        wr_String("  Vrnjeno: " + sToReturn + " EUR\n");
                    }
                }

                wr_NewLine(1);
                wr_String("Številka računa za FURS:\n");
                wr_String(FursD_BussinesPremiseID + "-" + ElectronicDevice_ID + "-" + xInvoiceData.NumberInFinancialYear.ToString());
                wr_NewLine(1);
                wr_String("Oseba, ki je izdala račun:\n");
                wr_String(xInvoiceData.Invoice_Author.FirstName + " " + xInvoiceData.Invoice_Author.LastName);

                if (xInvoiceData.AddOnDI.m_FURS.FURS_QR_v != null)
                {
                    if (xInvoiceData.AddOnDI.m_FURS.FURS_Image_QRcode != null)
                    {
                        //Size size = new Size(32, 32);
                        //Image img_new = StaticLib.Func.resizeImage(xInvoiceData.FURS_Response_Data.Image_QRcode, size, System.Drawing.Imaging.ImageFormat.Bmp, System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
                        //byte[] barr = StaticLib.Func.imageToByteArray(img_new);
                        wr_NewLine(1);
                        wr_String("ZOI:" + xInvoiceData.AddOnDI.m_FURS.FURS_ZOI_v.v + "\n");
                        wr_String("EOR:" + xInvoiceData.AddOnDI.m_FURS.FURS_EOR_v.v + "\n");
                        wr_NewLine(1);
                        byte[] barr = StaticLib.Func.imageToByteArray(xInvoiceData.AddOnDI.m_FURS.FURS_Image_QRcode);
                        wr_BitmapByteArray(barr, 180);
                    }
                }

                wr_NewLine(6);
                PartialCutPaper();

                if (PrintInBuffer)
                {
                    Print_PrinterBuffer();
                }

                string s_journal_invoice_type = lngRPM.s_journal_invoice_type_Print.s;
                string s_journal_invoice_description = PrinterName;
                f_Journal_DocInvoice.Write(xInvoiceData.DocInvoice_ID, GlobalData.Atom_WorkPeriod_ID, s_journal_invoice_type, s_journal_invoice_description, null, ref journal_docinvoice_id);
            }
            catch (Exception ex)
            {
                string s_journal_invoice_type = lngRPM.s_journal_invoice_type_PrintError.s + PrinterName + "\nErr=" + ex.Message;
                string s_journal_invoice_description = PrinterName;
                f_Journal_DocInvoice.Write(xInvoiceData.DocInvoice_ID, GlobalData.Atom_WorkPeriod_ID, s_journal_invoice_type, s_journal_invoice_description, null, ref journal_docinvoice_id);
            }
        }
Пример #2
0
        public bool Read_DocInvoice()
        {
            string sql = null;
            if (IsDocInvoice)
            {
                AddOnDI.DocInvoice_Reference_ID_v = null;
                if (AddOnDI.b_FVI_SLO)
                {
                    sql = @"select
                                pi.ID as DocInvoice_ID,
                                pi.FinancialYear,
                                pi.NumberInFinancialYear,
                                pi.Draft,
                                mpay.PaymentType,
                                GrossSum,
                                TaxSum,
                                NetSum,
                                ao.Name,
                                ao.Tax_ID,
                                ao.Registration_ID,
                                Atom_cStreetName_Org.StreetName,
                                Atom_cHouseNumber_Org.HouseNumber,
                                Atom_cCity_Org.City,
                                Atom_cZIP_Org.ZIP,
                                Atom_cCountry_Org.Country,
                                Atom_cState_Org.State,
                                cEmail_Org.Email,
                                aorgd_hp.HomePage,
                                cPhoneNumber_Org.PhoneNumber,
                                cFaxNumber_Org.FaxNumber,
                                aorgd.BankName,
                                aorgd.TRR,
                                aoff.Name as Atom_Office_Name,
                                apfn.FirstName as My_Organisation_Person_FirstName,
                                apln.LastName as My_Organisation_Person_LastName,
                                ap.ID as Atom_MyOrganisation_Person_ID,
                                ao.Tax_ID as My_Organisation_Tax_ID,
                                ap.CardNumber,
                                amcp.UserName as My_Organisation_Person_UserName,
                                amcp.Job as My_Organisation_Job,
                                Atom_Logo.Image_Hash as Logo_Hash,
                                Atom_Logo.Image_Data as Logo_Data,
                                Atom_Logo.Description as Logo_Description,
                                acusorg.ID as Atom_Customer_Org_ID,
                                acusper.ID as Atom_Customer_Person_ID,
                                jpi.EventTime,
                                jpit.Name as JOURNAL_DocInvoice_Type_Name,
                                JOURNAL_DocInvoice_$_dinv_$_fvisres.MessageID As JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$MessageID,
                                JOURNAL_DocInvoice_$_dinv_$_fvisres.UniqueInvoiceID As JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$UniqueInvoiceID,
                                JOURNAL_DocInvoice_$_dinv_$_fvisres.BarCodeValue As JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$BarCodeValue,
                                JOURNAL_DocInvoice_$_dinv_$_fvisbi.InvoiceNumber AS JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$InvoiceNumber,
                                JOURNAL_DocInvoice_$_dinv_$_fvisbi.SetNumber AS JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$SetNumber,
                                JOURNAL_DocInvoice_$_dinv_$_fvisbi.SerialNumber AS JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$SerialNumber,
                                pi.Storno,
                                pi.Invoice_Reference_Type,
                                pi.Invoice_Reference_ID
                                from JOURNAL_DocInvoice jpi
                                inner join JOURNAL_DocInvoice_Type jpit on jpi.JOURNAL_DocInvoice_Type_ID = jpit.ID and ((jpit.ID = " + GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceDraftTime.ID.ToString() + @") or (jpit.ID = " + GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceStornoTime.ID.ToString() + @"))
                                inner join DocInvoice pi on jpi.DocInvoice_ID = pi.ID
                                inner join Atom_WorkPeriod awp on jpi.Atom_WorkPeriod_ID = awp.ID
                                inner join Atom_myOrganisation_Person amcp on awp.Atom_myOrganisation_Person_ID = amcp.ID
                                inner join Atom_Person ap on ap.ID = amcp.Atom_Person_ID
                                inner join Atom_Office aoff on amcp.Atom_Office_ID = aoff.ID
                                inner join Atom_Office_Data aoffd on aoffd.Atom_Office_ID = aoff.ID
                                inner join Atom_myOrganisation amc on aoff.Atom_myOrganisation_ID = amc.ID
                                inner join Atom_OrganisationData aorgd on  amc.Atom_OrganisationData_ID = aorgd.ID
                                inner join Atom_Organisation ao on aorgd.Atom_Organisation_ID = ao.ID
                                LEFT JOIN FVI_SLO_Response JOURNAL_DocInvoice_$_dinv_$_fvisres ON JOURNAL_DocInvoice_$_dinv_$_fvisres.DocInvoice_ID = pi.ID
                                LEFT JOIN FVI_SLO_SalesBookInvoice JOURNAL_DocInvoice_$_dinv_$_fvisbi ON JOURNAL_DocInvoice_$_dinv_$_fvisbi.DocInvoice_ID = pi.ID
                                left join Atom_cFirstName apfn on ap.Atom_cFirstName_ID = apfn.ID
                                left join Atom_cLastName apln on ap.Atom_cLastName_ID = apln.ID
                                left join MethodOfPayment mpay on pi.MethodOfPayment_ID = mpay.ID
                                left join cOrgTYPE aorgd_cOrgTYPE on aorgd.cOrgTYPE_ID = aorgd_cOrgTYPE.ID
                                left join Atom_cAddress_Org acaorg on aorgd.Atom_cAddress_Org_ID = acaorg.ID
                                left join Atom_cStreetName_Org on acaorg.Atom_cStreetName_Org_ID = Atom_cStreetName_Org.ID
                                left join Atom_cHouseNumber_Org on acaorg.Atom_cHouseNumber_Org_ID = Atom_cHouseNumber_Org.ID
                                left join Atom_cCity_Org on acaorg.Atom_cCity_Org_ID = Atom_cCity_Org.ID
                                left join Atom_cZIP_Org on acaorg.Atom_cZIP_Org_ID = Atom_cZIP_Org.ID
                                left join Atom_cCountry_Org on acaorg.Atom_cCountry_Org_ID = Atom_cCountry_Org.ID
                                left join Atom_cState_Org on acaorg.Atom_cState_Org_ID = Atom_cState_Org.ID
                                left join cHomePage_Org on aorgd.cHomePage_Org_ID = cHomePage_Org.ID
                                left join cEmail_Org on aorgd.cEmail_Org_ID = cEmail_Org.ID
                                left join cHomePage_Org aorgd_hp  on aorgd.cHomePage_Org_ID = cHomePage_Org.ID
                                left join cFaxNumber_Org on aorgd.cFaxNumber_Org_ID = cFaxNumber_Org.ID
                                left join cPhoneNumber_Org on aorgd.cPhoneNumber_Org_ID = cPhoneNumber_Org.ID
                                left join Atom_Logo on aorgd.Atom_Logo_ID = Atom_Logo.ID
                                left join Atom_Customer_Org acusorg on acusorg.ID = pi.Atom_Customer_Org_ID
                                left join Atom_Customer_Person acusper on acusper.ID = pi.Atom_Customer_Person_ID
                                where pi.ID = " + DocInvoice_ID.ToString();
                }
                else
                {
                    sql = @"select
                                pi.ID as DocInvoice_ID,
                                pi.FinancialYear,
                                pi.NumberInFinancialYear,
                                pi.Draft,
                                mpay.PaymentType,
                                GrossSum,
                                TaxSum,
                                NetSum,
                                ao.Name,
                                ao.Tax_ID,
                                ao.Registration_ID,
                                Atom_cStreetName_Org.StreetName,
                                Atom_cHouseNumber_Org.HouseNumber,
                                Atom_cCity_Org.City,
                                Atom_cZIP_Org.ZIP,
                                Atom_cCountry_Org.Country,
                                Atom_cState_Org.State,
                                cEmail_Org.Email,
                                aorgd_hp.HomePage,
                                cPhoneNumber_Org.PhoneNumber,
                                cFaxNumber_Org.FaxNumber,
                                aorgd.BankName,
                                aorgd.TRR,
                                aoff.Name as Atom_Office_Name,
                                apfn.FirstName as My_Organisation_Person_FirstName,
                                apln.LastName as My_Organisation_Person_LastName,
                                ap.ID as Atom_MyOrganisation_Person_ID,
                                ao.Tax_ID as My_Organisation_Tax_ID,
                                ap.CardNumber,
                                amcp.UserName as My_Organisation_Person_UserName,
                                amcp.Job as My_Organisation_Job,
                                Atom_Logo.Image_Hash as Logo_Hash,
                                Atom_Logo.Image_Data as Logo_Data,
                                Atom_Logo.Description as Logo_Description,
                                acusorg.ID as Atom_Customer_Org_ID,
                                acusper.ID as Atom_Customer_Person_ID,
                                jpi.EventTime,
                                jpit.Name as JOURNAL_DocInvoice_Type_Name,
                                pi.Storno,
                                pi.Invoice_Reference_Type,
                                pi.Invoice_Reference_ID
                                from JOURNAL_DocInvoice jpi
                                inner join JOURNAL_DocInvoice_Type jpit on jpi.JOURNAL_DocInvoice_Type_ID = jpit.ID and ((jpit.ID = " + GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceDraftTime.ID.ToString() + @") or (jpit.ID = " + GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceStornoTime.ID.ToString() + @"))
                                inner join DocInvoice pi on jpi.DocInvoice_ID = pi.ID
                                inner join Atom_WorkPeriod awp on jpi.Atom_WorkPeriod_ID = awp.ID
                                inner join Atom_myOrganisation_Person amcp on Atom_WorkPeriod.Atom_myOrganisation_Person_ID = amcp.ID
                                inner join Atom_Person ap on ap.ID = amcp.Atom_Person_ID
                                inner join Atom_Office aoff on amcp.Atom_Office_ID = aoff.ID
                                inner join Atom_Office_Data aoffd on aoffd.Atom_Office_ID = aoff.ID
                                inner join Atom_myOrganisation amc on aoff.Atom_myOrganisation_ID = amc.ID
                                inner join Atom_OrganisationData aorgd on  amc.Atom_OrganisationData_ID = aorgd.ID
                                inner join Atom_Organisation ao on aorgd.Atom_Organisation_ID = ao.ID
                                left join Atom_cFirstName apfn on ap.Atom_cFirstName_ID = apfn.ID
                                left join Atom_cLastName apln on ap.Atom_cLastName_ID = apln.ID
                                left join MethodOfPayment mpay on pi.MethodOfPayment_ID = mpay.ID
                                left join cOrgTYPE aorgd_cOrgTYPE on aorgd.cOrgTYPE_ID = aorgd_cOrgTYPE.ID
                                left join Atom_cAddress_Org acaorg on aorgd.Atom_cAddress_Org_ID = acaorg.ID
                                left join Atom_cStreetName_Org on acaorg.Atom_cStreetName_Org_ID = Atom_cStreetName_Org.ID
                                left join Atom_cHouseNumber_Org on acaorg.Atom_cHouseNumber_Org_ID = Atom_cHouseNumber_Org.ID
                                left join Atom_cCity_Org on acaorg.Atom_cCity_Org_ID = Atom_cCity_Org.ID
                                left join Atom_cZIP_Org on acaorg.Atom_cZIP_Org_ID = Atom_cZIP_Org.ID
                                left join Atom_cCountry_Org on acaorg.Atom_cCountry_Org_ID = Atom_cCountry_Org.ID
                                left join Atom_cState_Org on acaorg.Atom_cState_Org_ID = Atom_cState_Org.ID
                                left join cHomePage_Org on aorgd.cHomePage_Org_ID = cHomePage_Org.ID
                                left join cEmail_Org on aorgd.cEmail_Org_ID = cEmail_Org.ID
                                left join cHomePage_Org aorgd_hp  on aorgd.cHomePage_Org_ID = cHomePage_Org.ID
                                left join cFaxNumber_Org on aorgd.cFaxNumber_Org_ID = cFaxNumber_Org.ID
                                left join cPhoneNumber_Org on aorgd.cPhoneNumber_Org_ID = cPhoneNumber_Org.ID
                                left join Atom_Logo on aorgd.Atom_Logo_ID = Atom_Logo.ID
                                left join Atom_Customer_Org acusorg on acusorg.ID = pi.Atom_Customer_Org_ID
                                left join Atom_Customer_Person acusper on acusper.ID = pi.Atom_Customer_Person_ID
                                where pi.ID = " + DocInvoice_ID.ToString();
                    }
                }
                else if (IsDocProformaInvoice)
                {
                sql = @"select
                                pi.ID as DocProformaInvoice_ID,
                                pi.FinancialYear,
                                pi.NumberInFinancialYear,
                                pi.Draft,
                                mpay.PaymentType,
                                GrossSum,
                                TaxSum,
                                NetSum,
                                ao.Name,
                                ao.Tax_ID,
                                ao.Registration_ID,
                                Atom_cStreetName_Org.StreetName,
                                Atom_cHouseNumber_Org.HouseNumber,
                                Atom_cCity_Org.City,
                                Atom_cZIP_Org.ZIP,
                                Atom_cCountry_Org.Country,
                                Atom_cState_Org.State,
                                cEmail_Org.Email,
                                aorgd_hp.HomePage,
                                cPhoneNumber_Org.PhoneNumber,
                                cFaxNumber_Org.FaxNumber,
                                aorgd.BankName,
                                aorgd.TRR,
                                aoff.Name as Atom_Office_Name,
                                apfn.FirstName as My_Organisation_Person_FirstName,
                                apln.LastName as My_Organisation_Person_LastName,
                                ap.ID as Atom_MyOrganisation_Person_ID,
                                ao.Tax_ID as My_Organisation_Tax_ID,
                                ap.CardNumber,
                                amcp.UserName as My_Organisation_Person_UserName,
                                amcp.Job as My_Organisation_Job,
                                Atom_Logo.Image_Hash as Logo_Hash,
                                Atom_Logo.Image_Data as Logo_Data,
                                Atom_Logo.Description as Logo_Description,
                                acusorg.ID as Atom_Customer_Org_ID,
                                acusper.ID as Atom_Customer_Person_ID,
                                jpi.EventTime,
                                jpit.Name as JOURNAL_DocProformaInvoice_Type_Name
                                from JOURNAL_DocProformaInvoice jpi
                                inner join JOURNAL_DocProformaInvoice_Type jpit on jpi.JOURNAL_DocProformaInvoice_Type_ID = jpit.ID and (jpit.ID = " + GlobalData.JOURNAL_DocProformaInvoice_Type_definitions.ProformaInvoiceDraftTime.ID.ToString() + @")
                                inner join DocProformaInvoice pi on jpi.DocProformaInvoice_ID = pi.ID
                                inner join Atom_WorkPeriod awp on jpi.Atom_WorkPeriod_ID = awp.ID
                                inner join Atom_myOrganisation_Person amcp on awp.Atom_myOrganisation_Person_ID = amcp.ID
                                inner join Atom_Person ap on ap.ID = amcp.Atom_Person_ID
                                inner join Atom_Office aoff on amcp.Atom_Office_ID = aoff.ID
                                inner join Atom_Office_Data aoffd on aoffd.Atom_Office_ID = aoff.ID
                                inner join Atom_myOrganisation amc on aoff.Atom_myOrganisation_ID = amc.ID
                                inner join Atom_OrganisationData aorgd on  amc.Atom_OrganisationData_ID = aorgd.ID
                                inner join Atom_Organisation ao on aorgd.Atom_Organisation_ID = ao.ID
                                left join Atom_cFirstName apfn on ap.Atom_cFirstName_ID = apfn.ID
                                left join Atom_cLastName apln on ap.Atom_cLastName_ID = apln.ID
                                left join MethodOfPayment mpay on pi.MethodOfPayment_ID = mpay.ID
                                left join cOrgTYPE aorgd_cOrgTYPE on aorgd.cOrgTYPE_ID = aorgd_cOrgTYPE.ID
                                left join Atom_cAddress_Org acaorg on aorgd.Atom_cAddress_Org_ID = acaorg.ID
                                left join Atom_cStreetName_Org on acaorg.Atom_cStreetName_Org_ID = Atom_cStreetName_Org.ID
                                left join Atom_cHouseNumber_Org on acaorg.Atom_cHouseNumber_Org_ID = Atom_cHouseNumber_Org.ID
                                left join Atom_cCity_Org on acaorg.Atom_cCity_Org_ID = Atom_cCity_Org.ID
                                left join Atom_cZIP_Org on acaorg.Atom_cZIP_Org_ID = Atom_cZIP_Org.ID
                                left join Atom_cCountry_Org on acaorg.Atom_cCountry_Org_ID = Atom_cCountry_Org.ID
                                left join Atom_cState_Org on acaorg.Atom_cState_Org_ID = Atom_cState_Org.ID
                                left join cHomePage_Org on aorgd.cHomePage_Org_ID = cHomePage_Org.ID
                                left join cEmail_Org on aorgd.cEmail_Org_ID = cEmail_Org.ID
                                left join cHomePage_Org aorgd_hp  on aorgd.cHomePage_Org_ID = cHomePage_Org.ID
                                left join cFaxNumber_Org on aorgd.cFaxNumber_Org_ID = cFaxNumber_Org.ID
                                left join cPhoneNumber_Org on aorgd.cPhoneNumber_Org_ID = cPhoneNumber_Org.ID
                                left join Atom_Logo on aorgd.Atom_Logo_ID = Atom_Logo.ID
                                left join Atom_Customer_Org acusorg on acusorg.ID = pi.Atom_Customer_Org_ID
                                left join Atom_Customer_Person acusper on acusper.ID = pi.Atom_Customer_Person_ID
                                where pi.ID = " + DocInvoice_ID.ToString();
            }
            else
            {
                LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:DocInvoice=" + DocInvoice + " not implemented.");
                return false;
            }

            string Err = null;
            if (DBSync.DBSync.ReadDataTable(ref dt_DocInvoice, sql, ref Err))
            {
                if (dt_DocInvoice.Rows.Count == 1)
                {
                    try
                    {
                        Draft = DBTypes.tf._set_bool(dt_DocInvoice.Rows[0]["Draft"]);
                        if (IsDocInvoice)
                        {
                            AddOnDI.Invoice_Storno_v = DBTypes.tf.set_bool(dt_DocInvoice.Rows[0]["Storno"]);
                            AddOnDI.Invoice_Reference_Type_v = DBTypes.tf.set_string(dt_DocInvoice.Rows[0]["Invoice_Reference_Type"]);
                            AddOnDI.DocInvoice_Reference_ID_v = DBTypes.tf.set_long(dt_DocInvoice.Rows[0]["Invoice_Reference_ID"]);
                        }
                        else
                        {
                        }
                        DocInvoice_ID_v = DBTypes.tf.set_long(dt_DocInvoice.Rows[0][DocInvoice+"_ID"]);
                        DateTime_v EventTime_v = DBTypes.tf.set_DateTime(dt_DocInvoice.Rows[0]["EventTime"]);
                        string_v EventName_v = DBTypes.tf.set_string(dt_DocInvoice.Rows[0]["JOURNAL_"+DocInvoice+"_Type_Name"]);

                        if (Draft)
                        {
                            this.m_eType = eType.DRAFT_INVOICE;
                        }
                        else
                        {
                            if (DocInvoice_ID_v != null)
                            {
                                    if (IsDocInvoice)
                                    {
                                        if (EventName_v != null)
                                        {
                                            if (EventName_v.v.Equals("InvoiceTime"))
                                            {
                                                this.m_eType = eType.INVOICE;
                                                this.IssueDate_v = EventTime_v.Clone();
                                            }
                                            else if (EventName_v.v.Equals("InvoiceStornoTime"))
                                            {
                                                this.m_eType = eType.STORNO;
                                                AddOnDI.StornoIssueDate_v = EventTime_v.Clone();
                                                if (AddOnDI.DocInvoice_Reference_ID_v != null)
                                                {
                                                    if (IssueDate_v == null)
                                                    {
                                                        sql = "select EventTime from JOURNAL_DocInvoice where DocInvoice_ID = " + AddOnDI.DocInvoice_Reference_ID_v.v.ToString() + " and JOURNAL_DocInvoice_Type_ID = " + GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceTime.ID.ToString();
                                                        DataTable dt = new DataTable();
                                                        if (DBSync.DBSync.ReadDataTable(ref dt, sql, ref Err))
                                                        {
                                                            if (dt.Rows.Count == 1)
                                                            {
                                                                IssueDate_v = DBTypes.tf.set_DateTime(dt.Rows[0]["EventTime"]);
                                                            }
                                                            else
                                                            {
                                                                LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:this error should not happen! EventTime for InvoiceTime must be defined!");
                                                            }

                                                        }
                                                        else
                                                        {
                                                            LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:sql=" + sql + "\r\nERR=" + Err);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:this error should not happen! DocInvoice_Reference_ID_v must be defined!");
                                                }
                                            }
                                            else
                                            {
                                                if (IssueDate_v == null)
                                                {

                                                    sql = "select EventTime from JOURNAL_DocInvoice where DocInvoice_ID = " + DocInvoice_ID.ToString() + " and JOURNAL_DocInvoice_Type_ID = " + GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceTime.ID.ToString();
                                                    DataTable dt = new DataTable();
                                                    if (DBSync.DBSync.ReadDataTable(ref dt, sql, ref Err))
                                                    {
                                                        if (dt.Rows.Count > 0)
                                                        {
                                                            IssueDate_v = DBTypes.tf.set_DateTime(dt.Rows[0]["EventTime"]);
                                                            if (dt.Rows.Count != 1)
                                                            {
                                                                LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:this error should not happen! EventTime for InvoiceTime must be defined!");
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:sql=" + sql + "\r\nERR=" + Err);
                                                    }
                                                }
                                                this.m_eType = eType.UNKNOWN;
                                            }

                                        }
                                        else
                                        {
                                            LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:this error should not happen! EventName must be defined!");
                                        }
                                    }
                                    else if (IsDocProformaInvoice)
                                    {
                                        if (EventName_v != null)
                                        {
                                            if (EventName_v.v.Equals("ProformaInvoiceTime"))
                                            {
                                                this.m_eType = eType.INVOICE;
                                                this.IssueDate_v = EventTime_v.Clone();
                                            }
                                            else
                                            {
                                                if (IssueDate_v == null)
                                                {

                                                    sql = "select EventTime from JOURNAL_DocProformaInvoice where DocProformaInvoice_ID = " + DocInvoice_ID.ToString() + " and JOURNAL_DocProformaInvoice_Type_ID = " + GlobalData.JOURNAL_DocProformaInvoice_Type_definitions.ProformaInvoiceTime.ID.ToString();
                                                    DataTable dt = new DataTable();
                                                    if (DBSync.DBSync.ReadDataTable(ref dt, sql, ref Err))
                                                    {
                                                        if (dt.Rows.Count == 1)
                                                        {
                                                            IssueDate_v = DBTypes.tf.set_DateTime(dt.Rows[0]["EventTime"]);
                                                        }
                                                        else
                                                        {
                                                            LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:this error should not happen! EventTime for InvoiceTime must be defined!");
                                                        }

                                                    }
                                                    else
                                                    {
                                                        LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:sql=" + sql + "\r\nERR=" + Err);
                                                    }
                                                }

                                                this.m_eType = eType.UNKNOWN;
                                            }

                                        }
                                        else
                                        {
                                            LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:this error should not happen! EventName must be defined!");
                                        }
                                    }
                                    else
                                    {
                                        LogFile.Error.Show("ERROR:InvoiceData:Read_DocInvoice:DocInvoice="+DocInvoice+" not implemented.");
                                    }
                                }
                            else
                            {
                                this.m_eType = eType.UNKNOWN;
                            }
                        }

                        if (IsDocInvoice)
                        {
                            if (AddOnDI.Invoice_Reference_Type_v != null)
                            {
                                if (AddOnDI.Invoice_Reference_Type_v.v.Equals("STORNO"))
                                {
                                    if (AddOnDI.DocInvoice_Reference_ID_v != null)
                                    {
                                        AddOnDI.bInvoiceStorno = true;
                                    }
                                    else
                                    {
                                        LogFile.Error.Show("ERROR:usrc_Invoice_Preview:Read_DocProformaInvoice:DocProformaInvoice_Reference_ID_v can not be null when Invoice_Reference_Type_v equals 'STORNO'");
                                    }
                                }
                            }
                        }

                        GrossSum = DBTypes.tf._set_decimal(dt_DocInvoice.Rows[0]["GrossSum"]);
                        taxsum = DBTypes.tf._set_decimal(dt_DocInvoice.Rows[0]["TaxSum"]);
                        NetSum = DBTypes.tf._set_decimal(dt_DocInvoice.Rows[0]["NetSum"]);

                        if (IsDocInvoice)
                        {
                            if (AddOnDI.bInvoiceStorno)
                            {
                                if (GrossSum > 0) GrossSum = GrossSum * -1;
                                if (taxsum > 0) taxsum = taxsum * -1;
                                if (NetSum > 0) NetSum = NetSum * -1;
                            }
                            if (AddOnDI.b_FVI_SLO)
                            {

                                //this.FVI_SLO_RealEstateBP = new UniversalInvoice.FVI_SLO_RealEstateBP(lngToken.st_Invoice,
                                //                                                                             DBTypes.tf._set_int(dt_DocProformaInvoice.Rows[0]["BuildingNumber"]),
                                //                                                                             DBTypes.tf._set_int(dt_DocProformaInvoice.Rows[0]["BuildingSectionNumber"]),
                                //                                                                             DBTypes.tf._set_string(dt_DocProformaInvoice.Rows[0]["Community"]),
                                //                                                                             DBTypes.tf._set_int(dt_DocProformaInvoice.Rows[0]["CadastralNumber"]),
                                //                                                                             DBTypes.tf._set_DateTime(dt_DocProformaInvoice.Rows[0]["ValidityDate"]),
                                //                                                                             DBTypes.tf._set_string(dt_DocProformaInvoice.Rows[0]["ClosingTag"]),
                                //                                                                             DBTypes.tf._set_string(dt_DocProformaInvoice.Rows[0]["SoftwareSupplier_TaxNumber"]),
                                //                                                                             DBTypes.tf._set_string(dt_DocProformaInvoice.Rows[0]["PremiseType"])   );
                            }

                        }

                        //byte[] barr_logoData = (byte[])dt_DocProformaInvoice.Rows[0]["Logo_Data"];
                        MyOrganisation = new UniversalInvoice.Organisation(lngToken.st_My, DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["Name"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["Tax_ID"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["Registration_ID"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["Atom_Office_Name"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["BankName"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["TRR"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["Email"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["HomePage"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["PhoneNumber"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["FaxNumber"]),
                                                                   DBTypes.tf._set_byte_array(dt_DocInvoice.Rows[0]["Logo_Data"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["StreetName"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["HouseNumber"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["ZIP"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["City"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["Country"]),
                                                                   DBTypes.tf._set_string(dt_DocInvoice.Rows[0]["State"]));

                        FinancialYear = DBTypes.tf._set_int(dt_DocInvoice.Rows[0]["FinancialYear"]);
                        NumberInFinancialYear = DBTypes.tf._set_int(dt_DocInvoice.Rows[0]["NumberInFinancialYear"]);

                            if (IsDocInvoice)
                            {
                                if (AddOnDI.b_FVI_SLO)
                                {
                                    if (!Draft)
                                    {

                                    AddOnDI.m_FURS.FURS_ZOI_v = DBTypes.tf.set_string(dt_DocInvoice.Rows[0]["JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$MessageID"]);
                                    AddOnDI.m_FURS.FURS_EOR_v = DBTypes.tf.set_string(dt_DocInvoice.Rows[0]["JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$UniqueInvoiceID"]);
                                    AddOnDI.m_FURS.FURS_QR_v = DBTypes.tf.set_string(dt_DocInvoice.Rows[0]["JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$BarCodeValue"]);
                                    AddOnDI.m_FURS.FURS_SalesBookInvoice_InvoiceNumber_v = DBTypes.tf.set_string(dt_DocInvoice.Rows[0]["JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$InvoiceNumber"]);
                                    AddOnDI.m_FURS.FURS_SalesBookInvoice_SetNumber_v = DBTypes.tf.set_string(dt_DocInvoice.Rows[0]["JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$SetNumber"]);
                                    AddOnDI.m_FURS.FURS_SalesBookInvoice_SerialNumber = DBTypes.tf.set_string(dt_DocInvoice.Rows[0]["JOURNAL_DocInvoice_$_dinv_$_fvisbi_$$SerialNumber"]);
                                    }
                                }
                            }

                        object oAtom_MyOrganisation_Person_ID = dt_DocInvoice.Rows[0]["Atom_MyOrganisation_Person_ID"];
                        if (oAtom_MyOrganisation_Person_ID is long)
                        {
                            long Atom_MyOrganisation_Person_ID = (long)oAtom_MyOrganisation_Person_ID;
                            Invoice_Author = f_Atom_Person.GetData(lngToken.st_IssuerOfInvoice, Atom_MyOrganisation_Person_ID);
                        }

                        object oAtom_Customer_Org_ID = dt_DocInvoice.Rows[0]["Atom_Customer_Org_ID"];
                        if (oAtom_Customer_Org_ID is long)
                        {
                            long Atom_Customer_Org_ID = (long)oAtom_Customer_Org_ID;
                            CustomerOrganisation = f_Atom_Customer_Org.GetData(lngToken.st_Customer, Atom_Customer_Org_ID);
                        }
                        else
                        {
                            CustomerOrganisation = new UniversalInvoice.Organisation(lngToken.st_Customer);
                        }

                        if (dt_DocInvoice.Rows[0]["Atom_Customer_Person_ID"] is long)
                        {
                            long Atom_Customer_Person_ID = (long)dt_DocInvoice.Rows[0]["Atom_Customer_Person_ID"];
                            CustomerPerson = f_Atom_Customer_Person.GetData(lngToken.st_Customer, Atom_Customer_Person_ID);
                        }
                        else
                        {
                            CustomerPerson = new UniversalInvoice.Person(lngToken.st_Customer);
                        }

                        long xDoc_ID = DocInvoice_ID;
                        if (IsDocInvoice)
                        {
                            if (AddOnDI.DocInvoice_Reference_ID_v != null)
                            {
                                xDoc_ID = AddOnDI.DocInvoice_Reference_ID_v.v;
                            }
                        }

                        if (dbfunc.Read_ShopA_Price_Item_Table(DocInvoice,xDoc_ID, ref dt_ShopA_Items))
                        {
                            if (m_ShopABC.Read_ShopB_Price_Item_Table(xDoc_ID, ref dt_ShopB_Items))
                            {
                                List<object> xDocProformaInvoice_ShopC_Item_Data_LIST = new List<object>();
                                if (this.m_eType == eType.STORNO)
                                {
                                    if (!m_ShopABC.m_CurrentInvoice.m_Basket.Read_ShopC_Price_Item_Stock_Table(DocInvoice,xDoc_ID, ref xDocProformaInvoice_ShopC_Item_Data_LIST))
                                    {
                                        return false;
                                    }
                                }
                                else
                                {
                                    xDocProformaInvoice_ShopC_Item_Data_LIST = m_ShopABC.m_CurrentInvoice.m_Basket.m_DocInvoice_ShopC_Item_Data_LIST;
                                }

                                int iCountShopAItemsSold = dt_ShopA_Items.Rows.Count;
                                int iCountShopBItemsSold = dt_ShopB_Items.Rows.Count;

                                int iCountShopCItemsSold = xDocProformaInvoice_ShopC_Item_Data_LIST.Count;

                                ItemsSold = new UniversalInvoice.ItemSold[iCountShopAItemsSold + iCountShopBItemsSold + iCountShopCItemsSold];
                                taxSum = new StaticLib.TaxSum();

                                if (IsDocInvoice)
                                {
                                    Fill_Sold_ShopA_ItemsData(lngToken.st_Invoice, ref ItemsSold, 0, iCountShopAItemsSold, AddOnDI.bInvoiceStorno);
                                    Fill_Sold_ShopB_ItemsData(lngToken.st_Invoice, ref ItemsSold, iCountShopAItemsSold, iCountShopBItemsSold, AddOnDI.bInvoiceStorno);
                                    Fill_Sold_ShopC_ItemsData(xDocProformaInvoice_ShopC_Item_Data_LIST, lngToken.st_Invoice, ref ItemsSold, iCountShopAItemsSold + iCountShopBItemsSold, iCountShopCItemsSold, AddOnDI.bInvoiceStorno);
                                }
                                InvoiceToken = new UniversalInvoice.InvoiceToken();

                                InvoiceToken.tFiscalYear.Set(FinancialYear.ToString());
                                InvoiceToken.tInvoiceNumber.Set(NumberInFinancialYear.ToString());
                                InvoiceToken.tCashier.Set(CasshierName);

                                InvoiceToken.tStorno.Set("");
                                if (IsDocInvoice)
                                {
                                    if (AddOnDI.bInvoiceStorno)
                                    {
                                        InvoiceToken.tStorno.Set(lngRPM.s_STORNO.s);
                                    }
                                }

                                if (!Draft)
                                {
                                    string stime = IssueDate_v.v.Day.ToString() + "."
                                                    + IssueDate_v.v.Month.ToString() + "."
                                                    + IssueDate_v.v.Year.ToString() + " "
                                                    + IssueDate_v.v.Hour.ToString() + ":"
                                                    + IssueDate_v.v.Minute.ToString();
                                    InvoiceToken.tDateOfIssue.Set(stime);
                                    InvoiceToken.tDateOfMaturity.Set(stime);
                                }
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    catch (Exception ex)
                    {
                        LogFile.Error.Show("ERROR:usrc_Invoice_Preview:Read_DocProformaInvoice:Exception=" + ex.Message);
                        return false;
                    }
                }
                else
                {
                    LogFile.Error.Show("ERROR:usrc_Invoice_Preview:Read_DocProformaInvoice:dt_DocProformaInvoice.Rows.Count != 1! for DocProformaInvoice_ID=" + DocInvoice_ID.ToString() + "!\r\nsql = " + sql);
                    return false;
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:usrc_Invoice_Preview:Read_DocProformaInvoice:Err=" + Err);
                return false;
            }
        }