Beispiel #1
0
        public const string TRANSTYPE_ERH400 = "ERH400"; //Foreign Transaction


        public static bool GenerateFile(IEnumerable <CreditorTransPayment> paymentList, Company company, CreditorPaymentFormat paymentFormat, SQLCache bankAccountCache, SQLCache creditorCache, bool glJournalGenerated = false)
        {
            var bankStatement        = (BankStatement)bankAccountCache.Get(paymentFormat._BankAccount);
            var fileFormat           = new CreateBECFileFormatBase();
            var listofBankProperties = new List <DanishFormatFieldBase>();

            foreach (var tran in paymentList)
            {
                var creditor = (Uniconta.DataModel.Creditor)creditorCache.Get(tran.Account);

                if (tran.Paid || tran.OnHold || tran.ErrorInfo != BaseDocument.VALIDATE_OK)
                {
                    continue;
                }

                var newProp = fileFormat.CreateFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);
                if (newProp != null)
                {
                    listofBankProperties.Add(newProp);
                }
            }

            if (listofBankProperties.Count > 0)
            {
                var sfd = UtilDisplay.LoadSaveFileDialog;
                sfd.Filter = UtilFunctions.GetFilteredExtensions(FileextensionsTypes.CSV);

                var userClickedSave = sfd.ShowDialog();
                if (userClickedSave != true)
                {
                    return(false);
                }

                try
                {
#if !SILVERLIGHT
                    using (var stream = File.Create(sfd.FileName))
#else
                    using (var stream = sfd.OpenFile())
#endif
                    {
                        using (var sw = new StreamWriter(stream, Encoding.GetEncoding(1252)))
                        {
                            fileFormat.StreamToFile(listofBankProperties, sw);
                        }
                        stream.Close();
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    UnicontaMessageBox.Show(ex);
                }
            }
            else
            {
                UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecords"), Uniconta.ClientTools.Localization.lookup("Message"));
            }
            return(false);
        }
Beispiel #2
0
        public bool CreateFile(IEnumerable <VatOSSTable> listVatOSS)
        {
            var result = listVatOSS.Where(s => s.SystemInfo == VALIDATE_OK).ToList();


            if (result.Count > 0)
            {
                var sort = new VatOSSTableTypeSort();
                result.Sort(sort);

                var sfd = UtilDisplay.LoadSaveFileDialog;
                sfd.Filter = UtilFunctions.GetFilteredExtensions(FileextensionsTypes.CSV);
                var userClickedSave = sfd.ShowDialog();
                if (userClickedSave != true)
                {
                    return(false);
                }

                try
                {
                    using (var stream = File.Create(sfd.FileName))
                    {
                        var sw          = new StreamWriter(stream, Encoding.Default);
                        var sumOfAmount = StreamToFile(result, sw);
                        sw.Flush();
                    }
                }
                catch (Exception ex)
                {
                    UnicontaMessageBox.Show(ex);
                    return(false);
                }
            }
            return(true);
        }
 public CWImportToJournal(CrudAPI crudApi, string title = null)
 {
     DataContext = this;
     InitializeComponent();
     Title                      = title ?? Uniconta.ClientTools.Localization.lookup("Import");
     api                        = crudApi;
     lookupJournal.api          = crudApi;
     browseFile.Filter          = UtilFunctions.GetFilteredExtensions(FileextensionsTypes.CSV);
     browseFile.NotLoadFileInfo = true;
     InitCaches(crudApi);
 }
        public bool CreateFile(IEnumerable<EUSaleWithoutVAT> listOfEUSaleWithoutVAT)
        {
            var result = listOfEUSaleWithoutVAT.Where(s => s.SystemInfo == VALIDATE_OK).ToList();
            if (result.Count > 0)
            {
                // Estonian XML generating
                if (api.CompanyEntity._CountryId == CountryCode.Estonia)
                {
                    GenerateXmlReport(result, api);
                    return true;
                }

                var sfd = UtilDisplay.LoadSaveFileDialog;
                sfd.Filter = UtilFunctions.GetFilteredExtensions(FileextensionsTypes.CSV);
                var userClickedSave = sfd.ShowDialog();
                if (userClickedSave != true)
                    return false;

                try
                {
                    using (var stream = File.Create(sfd.FileName))
                    {
                        var sw = new StreamWriter(stream, Encoding.Default);
                        if (api.CompanyEntity._CountryId == CountryCode.Germany) //Erik
                        {
                            StreamToFileDE(result, sw);
                        }
                        else
                        {
                            CreateAndStreamFirstAndLast(result, sw, true, companyRegNo);
                            var sumOfAmount = StreamToFile(result, sw);
                            CreateAndStreamFirstAndLast(result, sw, false, companyRegNo, result.Count, sumOfAmount);
                        }
                        sw.Flush();
                    }
                }
                catch (Exception ex)
                {
                    UnicontaMessageBox.Show(ex);
                    return false;
                }
            }
            return true;
        }
Beispiel #5
0
        async void ReadOIOUBL()
        {
            readingOIOUBL = true;
#if !SILVERLIGHT
            try
            {
                var sfd = UtilDisplay.LoadOpenFileDialog;
                sfd.Filter = UtilFunctions.GetFilteredExtensions(FileextensionsTypes.XML);

                var userClickedSave = sfd.ShowDialog();
                if (userClickedSave != true)
                {
                    return;
                }

                using (var stream = File.Open(sfd.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var sr         = new StreamReader(stream);
                    var oioublText = sr.ReadToEnd();

                    var order = await OIOUBL.ReadInvoiceCreditNoteOrOrder(oioublText, creditors, api, true);

                    if (order == null)
                    {
                        ClearFields(initialOrder);
                        return;
                    }

                    order.SetMaster(api.CompanyEntity);
                    //PriceLookup?.OrderChanged(order);

                    var orderLines = order.Lines;
                    order.Lines = null;

                    ClearFields(order);

                    int countLine = 0;
                    foreach (var line in orderLines)
                    {
                        line.SetMaster(order);
                        line._LineNumber = ++countLine;
                    }

                    dgCreditorOrderLineGrid.ItemsSource = orderLines;

                    if (order.DocumentRef != 0)
                    {
                        UpdateVoucher(Order);
                    }
                }
                readingOIOUBL = false;
            }
            catch (Exception e)
            {
                readingOIOUBL = false;
                if (e.StackTrace.IndexOf("xmlserializer", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    UnicontaMessageBox.Show("The file is not a valid XSD schemas. For more information (validation info) use www.oioubl.net/validator/", Uniconta.ClientTools.Localization.lookup("Information"));
                }
                else
                {
                    UnicontaMessageBox.Show(e, Uniconta.ClientTools.Localization.lookup("Information"));
                }
            }
#endif
        }
Beispiel #6
0
        public static bool GenerateFile(IEnumerable <CreditorTransPayment> paymentList, Company company,
                                        CreditorPaymentFormat paymentFormat, SQLCache bankAccountCache, SQLCache creditorCache, bool glJournalGenerated = false)
        {
            var bankStatement        = (BankStatement)bankAccountCache.Get(paymentFormat._BankAccount);
            var fileFormat           = new CreateDanskeBankFileFormatBase();
            var listofBankProperties = new List <DanishFormatFieldBase>();

            foreach (var tran in paymentList)
            {
                var swiftCode   = tran._SWIFT ?? string.Empty;
                var countryCode = swiftCode.Length >= 6 ? swiftCode.Substring(4, 2) : string.Empty;
                var creditor    = (Uniconta.DataModel.Creditor)creditorCache.Get(tran.Account);

                if (countryCode != string.Empty && countryCode != BaseDocument.COUNTRY_DK)
                {
                    var newProp = fileFormat.CreateForeignFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);
                    if (newProp != null)
                    {
                        listofBankProperties.Add(newProp);
                    }
                }
                else
                {
                    var newProp = fileFormat.CreateDanishFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);
                    if (newProp != null)
                    {
                        listofBankProperties.Add(newProp);
                    }
                }
            }

            if (listofBankProperties.Count > 0)
            {
                var sfd = UtilDisplay.LoadSaveFileDialog;
                sfd.Filter = UtilFunctions.GetFilteredExtensions(FileextensionsTypes.CSV);


                var userClickedSave = sfd.ShowDialog();
                if (userClickedSave != true)
                {
                    return(false);
                }

                try
                {
#if !SILVERLIGHT
                    using (var stream = File.Create(sfd.FileName))
#else
                    using (var stream = sfd.OpenFile())
#endif
                    {
                        var sw = new StreamWriter(stream, Encoding.Default);
                        fileFormat.StreamToDanishFile(listofBankProperties, sw);
                        fileFormat.StreamToForeignFile(listofBankProperties, sw);
                        sw.Flush();
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    UnicontaMessageBox.Show(ex);
                }
            }
            else
            {
                UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecords"), Uniconta.ClientTools.Localization.lookup("Message"));
            }
            return(false);
        }
        public static bool GenerateFile(IEnumerable <CreditorTransPayment> paymentList, Company company,
                                        CreditorPaymentFormat paymentFormat, SQLCache bankAccountCache, SQLCache creditorCache, bool glJournalGenerated = false)
        {
            var bankStatement        = (BankStatement)bankAccountCache.Get(paymentFormat._BankAccount);
            var fileFormat           = new CreateBankDataFileFormatBase();
            var listofBankProperties = new List <DanishFormatFieldBase>();

            foreach (var tran in paymentList)
            {
                var creditor = (Uniconta.DataModel.Creditor)creditorCache.Get(tran.Account);

                if (tran._PaymentMethod == PaymentTypes.IBAN)
                {
                    var newProp = fileFormat.CreateForeignFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);
                    if (newProp != null)
                    {
                        listofBankProperties.Add(newProp);
                    }

                    var newProp2 = fileFormat.SecondaryCreateForeignFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);
                    if (newProp != null)
                    {
                        listofBankProperties.Add(newProp2);
                    }
                }
                else if ((tran._PaymentMethod != PaymentTypes.IBAN) && (tran._PaymentMethod != PaymentTypes.VendorBankAccount))
                {
                    var newProp = fileFormat.CreateIndbetalingskortFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);

                    if (newProp != null)
                    {
                        listofBankProperties.Add(newProp);
                    }
                }
                else if (tran._PaymentMethod == PaymentTypes.VendorBankAccount)
                {
                    var swiftCode   = tran._SWIFT ?? string.Empty;
                    var countryCode = swiftCode.Length >= 6 ? swiftCode.Substring(4, 2) : string.Empty;

                    if (countryCode != string.Empty && countryCode != BaseDocument.COUNTRY_DK)
                    {
                        var newProp = fileFormat.CreateForeignFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);
                        if (newProp != null)
                        {
                            listofBankProperties.Add(newProp);
                        }

                        var newProp2 = fileFormat.SecondaryCreateForeignFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);
                        if (newProp != null)
                        {
                            listofBankProperties.Add(newProp2);
                        }
                    }
                    else
                    {
                        var newProp = fileFormat.CreateDomesticFormatField(tran, paymentFormat, bankStatement, creditor, company, glJournalGenerated);
                        if (newProp != null)
                        {
                            listofBankProperties.Add(newProp);
                        }

                        var newProp2 = fileFormat.SecondaryCreateDomesticFormatField(tran, paymentFormat, bankStatement, company, glJournalGenerated);
                        if (newProp != null)
                        {
                            listofBankProperties.Add(newProp2);
                        }
                    }
                }
            }

            if (listofBankProperties.Count > 0)
            {
                var sfd = UtilDisplay.LoadSaveFileDialog;
                sfd.Filter = UtilFunctions.GetFilteredExtensions(FileextensionsTypes.TXT);

                var userClickedSave = sfd.ShowDialog();
                if (userClickedSave != true)
                {
                    return(false);
                }

                try
                {
#if !SILVERLIGHT
                    using (var stream = File.Create(sfd.FileName))
#else
                    using (var stream = sfd.OpenFile())
#endif
                    {
                        using (var sw = new StreamWriter(stream, Encoding.GetEncoding(1252)))
                        {
                            CreateStartAndEnd(listofBankProperties, sw, true);
                            fileFormat.StreamToDomesticFile(listofBankProperties, sw);
                            fileFormat.StreamToForeignFile(listofBankProperties, sw);
                            fileFormat.StreamToIndbetalingskortFile(listofBankProperties, sw);
                            CreateStartAndEnd(listofBankProperties, sw, false);
                        }
                        stream.Close();
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    UnicontaMessageBox.Show(ex);
                }
            }
            else
            {
                UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("There are no payments!\nPlease check the System info column."), Uniconta.ClientTools.Localization.lookup("Warning"));
            }
            return(false);
        }
Beispiel #8
0
        public async void ReadOIOUBL(bool oneOrMultiple)
        {
#if !SILVERLIGHT
            try
            {
                if (creditorCache == null)
                {
                    creditorCache = api.GetCache(typeof(Uniconta.DataModel.Creditor)) ?? await api.LoadCache(typeof(Uniconta.DataModel.Creditor));
                }

                var orderlist = dgCreditorOrdersGrid.ItemsSource as List <CreditorOrderClient>;

                if (!oneOrMultiple)
                {
                    var    orderlistToAddToGrid = new List <CreditorOrderClient>();
                    string listOfFailedFiles    = null;

                    var openFolderDialog = UtilDisplay.LoadFolderBrowserDialog;
                    if (openFolderDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }

                    string[] files = Directory.GetFiles(openFolderDialog.SelectedPath);

                    foreach (string file in files)
                    {
                        var xmlText = File.ReadAllText(file);
                        var order   = await OIOUBL.ReadInvoiceCreditNoteOrOrder(xmlText, creditorCache, api, oneOrMultiple);

                        if (order == null)
                        {
                            listOfFailedFiles += string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("ViewerFailed"), file + Environment.NewLine);
                            continue;
                        }

                        var orderlines = order.Lines;
                        order.Lines = null;

                        var err = await api.Insert(order);

                        if (err != ErrorCodes.Succes)
                        {
                            listOfFailedFiles += string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("ViewerFailed"), file + Environment.NewLine);
                            continue;
                        }

                        int countLine = 0;
                        foreach (var line in orderlines)
                        {
                            line.SetMaster(order);
                            line._LineNumber = ++countLine;
                        }

                        var err2 = await api.Insert(orderlines);

                        if (err2 != ErrorCodes.Succes)
                        {
                            listOfFailedFiles += string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("ViewerFailed"), file + Environment.NewLine);
                            continue;
                        }

                        order.Lines = orderlines;
                        orderlistToAddToGrid.Add(order);
                    }

                    if (orderlist == null || orderlist.Count == 0)
                    {
                        orderlist = orderlistToAddToGrid;
                    }
                    else
                    {
                        orderlist.AddRange(orderlistToAddToGrid);
                    }

                    dgCreditorOrdersGrid.ItemsSource = orderlist;

                    if (listOfFailedFiles != null)
                    {
                        listOfFailedFiles = listOfFailedFiles + Uniconta.ClientTools.Localization.lookup("RunFileIndividual");
                        UnicontaMessageBox.Show(listOfFailedFiles, Uniconta.ClientTools.Localization.lookup("Error"));
                    }
                }
                else
                {
                    var sfd = UtilDisplay.LoadOpenFileDialog;
                    sfd.Filter = UtilFunctions.GetFilteredExtensions(FileextensionsTypes.XML);

                    var userClickedSave = sfd.ShowDialog();
                    if (userClickedSave != true)
                    {
                        return;
                    }

                    using (var stream = File.Open(sfd.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        var sr         = new StreamReader(stream);
                        var oioublText = await sr.ReadToEndAsync();

                        stream.Close();

                        var order = await OIOUBL.ReadInvoiceCreditNoteOrOrder(oioublText, creditorCache, api, oneOrMultiple);

                        if (order == null)
                        {
                            return;
                        }

                        var orderlines = order.Lines;
                        order.Lines = null;

                        var err = await api.Insert(order);

                        if (err != ErrorCodes.Succes)
                        {
                            UtilDisplay.ShowErrorCode(err);
                            return;
                        }

                        int countLine = 0;
                        foreach (var line in orderlines)
                        {
                            line.SetMaster(order);
                            line._LineNumber = ++countLine;
                        }

                        err = await api.Insert(orderlines);

                        if (err != ErrorCodes.Succes)
                        {
                            UtilDisplay.ShowErrorCode(err);
                            return;
                        }

                        if (orderlist == null || orderlist.Count == 0)
                        {
                            orderlist = new List <CreditorOrderClient>();
                        }

                        orderlist.Add(order);

                        dgCreditorOrdersGrid.ItemsSource = orderlist;
                    }
                }
            }
            catch (Exception ex)
            {
                UnicontaMessageBox.Show(ex);
            }
#endif
        }