Beispiel #1
0
        public bool CreateArticle(string articleNo, string name, int priceCalcMethodsNo, int postingTemplate, int stockProfileNo)
        {
            _articleComponent.bcInitData();
            _articleComponent.bcSetInitialValues();

            _articleComponent.bcSetValueFromStr((int)Article_Properties.ART_ArticleNo, articleNo);
            _articleComponent.bcUpdateStr((int)Article_Properties.ART_Name, name);
            // Konteringsmall
            _articleComponent.bcUpdateInt((int)Article_Properties.ART_PostingTemplateNo, postingTemplate);
            // Prisprofil
            _articleComponent.bcUpdateInt((int)Article_Properties.ART_PriceCalcMethodsNo, priceCalcMethodsNo);
            // Lagerprofil
            _articleComponent.bcUpdateInt((int)Article_Properties.ART_StockProfileNo, stockProfileNo);

            var errCode = _articleComponent.bcAddNew();

            if (errCode != 0)
            {
                _articleComponent.bcCancelRecord();
                LogFileWriter.WriteLine(string.Format("Attempt to create article '{0} - {1}' failed. Code {2} - {3}", articleNo, name, errCode, _articleComponent.bcGetMessageText(errCode)));
                return(false);
            }

            return(true);
        }
 /// <inheritdoc />
 public ParseOutput ProcessPdf(string pdfFileName)
 {
     LogFileWriter.WriteLine($"Processed file {pdfFileName}.");
     return(new ParseOutput
     {
         DocumentWasStored = true
     });
 }
Beispiel #3
0
        private static void HandleLoginResult(int loginCode, string clientName, string bapiKey)
        {
            if (loginCode == 0)
            {
                return;
            }

            LogFileWriter.WriteLine("ERROR: Failed to connect to Visma Global. Client=" + clientName + " Bapi=" + bapiKey);
            LogFileWriter.WriteLine(string.Format("Code {0} - {1}", loginCode, TranslateLoginCodeToMessage(loginCode)));
        }
Beispiel #4
0
 private void LogErrorMessage(int errCode)
 {
     if (errCode == 4)
     {
         LogFileWriter.WriteLine("Did not find any invoices to transfer.");
     }
     else if (errCode > 99)
     {
         LogFileWriter.WriteLine(string.Format("Failed to get invoices. Code {0} - {1}", errCode, _invoiceComp.bcGetMessageText(errCode)));
     }
 }
        private static ParseOutput TryParse(string pdfFilePath, string converterFileName)
        {
            int outputLineCount;
            var csvFileName    = FileHelper.GetFileNameFromPath(pdfFilePath) + ".csv";
            var outputFilePath = Settings.CsvOutputFolderPath + csvFileName;

            lock (_myLock) {
                // Prepare ConverterX instance
                ConverterX cnv = new ConverterX();
                try {
                    cnv.OpenProject(Settings.TextConverterProjectFolderPath + converterFileName);
                }
                catch {
                    LogFileWriter.WriteErrorLine("Open failed (" + pdfFilePath + ")");
                    LogFileWriter.WriteErrorLine("Reattempting to open: " + FileHelper.GetFileNameFromPath(pdfFilePath) + ".csv (" + DateTime.Now.ToString("HH:mm:ss") + ")");
                    cnv.OpenProject(Settings.TextConverterProjectFolderPath + converterFileName);
                }
                cnv.SetInputFile(pdfFilePath);

                // Extract data from PDF File
                ITDataSource src = cnv.GetOutputDS();

                // Prepare for Csv creation
                src.SetDS(outputFilePath, string.Empty);
                src.csv_include_column_names = true;
                src.csv_col_separator        = "|";
                cnv.SetBatch(0);

                // Create CSV extract file
                outputLineCount = cnv.Convert("");
                var csvMessage = new StringBuilder();
                csvMessage.AppendFormat("Output: {0} \t\t Lines: {1}\r\n", csvFileName, outputLineCount);
                LogFileWriter.WriteLine(csvMessage.ToString());

                // Close ConverterX instance
                cnv.Close();
            }

            return(new ParseOutput {
                IsMiscDeposit = false,
                PdfFileName = pdfFilePath,
                ConverterName = converterFileName,
                CSVFileName = csvFileName,
                CSVRowCount = outputLineCount
            });
        }
Beispiel #6
0
        public static void ImportCsvFile(string statementGuid, string csvFilename, string pdfFileName, bool isMiscDeposit, bool isBonusTransaction)
        {
            LogFileWriter.WriteLine("Staging data from: " + csvFilename);

            using (var csvFile = new StreamReader(csvFilename))
            {
                var currentLine = csvFile.ReadLine();
                try
                {
                    var skipLine = true;
                    while (currentLine != null)
                    {
                        if (skipLine)
                        {
                            // skip the header row
                            skipLine = false;
                        }
                        else
                        {
                            if (isMiscDeposit)
                            {
                                // Import current Csv Deposit
                                ImportCsvDeposit(statementGuid, currentLine);
                            }
                            else if (isBonusTransaction)
                            {
                                // Import current Csv Transaction
                                ImportCsvBonusTransaction(statementGuid, pdfFileName, currentLine);
                            }
                            else
                            {
                                // Import current Csv Transaction
                                ImportCsvTransaction(statementGuid, pdfFileName, currentLine);
                            }
                        }

                        currentLine = csvFile.ReadLine();
                    }
                }
                catch (Exception exception)
                {
                    var message = $"Error reading CSV file {csvFilename} --> line. ({currentLine})";
                    throw new ApplicationException(message, exception);
                }
            }
        }
Beispiel #7
0
        public IList <TransferItem> GetInvoices(int chainNo, int loanReturnNo)
        {
            InitializeComponents();

            var where = CreateFilter(chainNo, loanReturnNo);
            LogFileWriter.WriteLine(string.Format("Setting filter before fetching invoices: '{0}'", where));
            _invoiceComp.bcSetFilterRequeryStr(where);

            var start   = DateTime.Now;
            var errCode = _invoiceComp.bcFetchFirst(0);

            LogFileWriter.WriteLine(string.Format("Time spent fetching invoices: {0}", DateTime.Now.Subtract(start)));
            LogFileWriter.WriteLine(string.Format("bcGetNoOfRecords = {0}", _invoiceComp.bcGetNoOfRecords()));

            if (errCode != 0)
            {
                LogErrorMessage(errCode);
                return(new List <TransferItem>());
            }

            var list = new List <TransferItem>();

            do
            {
                var item = new TransferItem
                {
                    InvoiceNo    = _invoiceComp.bcGetInt((int)CustomerOrderCopy_Properties.COP_InvoiceNo),
                    OrderNo      = _invoiceComp.bcGetStr((int)CustomerOrderCopy_Properties.COP_OrderCopyNo),
                    CustomerNo   = _invoiceComp.bcGetInt((int)CustomerOrderCopy_Properties.COP_CustomerNo),
                    CustomerName = _invoiceComp.bcGetStr((int)CustomerOrderCopy_Properties.COP_DeliveryCustomerName),
                    CustomerContactNameForInvoice = _invoiceComp.bcGetStr((int)CustomerOrderCopy_Properties.COP_NameContactNoInvoice)
                };

                start      = DateTime.Now;
                item.Lines = GetInvoiceLines(item.InvoiceNo);
                LogFileWriter.WriteLine(string.Format("Time spent fetching lines for invoice {0}: {1}", item.InvoiceNo, DateTime.Now.Subtract(start)));

                if (item.Lines.Count > 0)
                {
                    list.Add(item);
                }
            } while (_invoiceComp.bcFetchNext(0) == 0);

            return(list);
        }
        public string CreateSalesOrderFromInvoice(TransferItem transferItem)
        {
            var salesOrderComp = _vgConnection.GetSalesOrderServerComponent();

            _colOrderNo   = salesOrderComp.bcGetTableObjectName((int)CustomerOrderLine_Properties.COL_OrderNo);
            _colArticleNo = salesOrderComp.bcGetTableObjectName((int)CustomerOrderLine_Properties.COL_ArticleNo);
            _colName      = salesOrderComp.bcGetTableObjectName((int)CustomerOrderLine_Properties.COL_Name);

            salesOrderComp.bcSetDefaultValuesActive(1);

            salesOrderComp.bcInitNewOrder(string.Empty);
            transferItem.OrderNoInDestinationClient = salesOrderComp.bcGetStr((int)CustomerOrder_Properties.COR_OrderNo);

            salesOrderComp.bcUpdateInt((int)CustomerOrder_Properties.COR_CustomerNo, transferItem.CustomerNo);
            salesOrderComp.bcUpdateStr((int)CustomerOrder_Properties.COR_CustomerPurchaseNo, transferItem.OrderNo);
            if (!string.IsNullOrWhiteSpace(transferItem.CustomerContactNameForInvoice))
            {
                salesOrderComp.bcUpdateStr((int)CustomerOrder_Properties.COR_NameContactNoInvoice, transferItem.CustomerContactNameForInvoice);
            }

            var allLinesCreated = true;
            int errCode;

            foreach (var line in transferItem.Lines)
            {
                var lineIsValid = true;
                var artCode     = salesOrderComp.bcUpdateStr((int)CustomerOrderLine_Properties.COL_ArticleNo, line.ArticleNo);
                salesOrderComp.bcUpdateStr((int)CustomerOrderLine_Properties.COL_Name, line.ArticleName);
                var priceCode = salesOrderComp.bcUpdateDouble((int)CustomerOrderLine_Properties.COL_NetPrice, (double)line.Price);

                if (line.DiscountInPercent1 > 0)
                {
                    salesOrderComp.bcUpdateDouble((int)CustomerOrderLine_Properties.COL_DiscountI, (double)line.DiscountInPercent1);
                }

                var qtyCode = salesOrderComp.bcUpdateDouble((int)CustomerOrderLine_Properties.COL_Quantity, (double)line.Quantity);

                // Setting DiscountII after Quantity because that's how it's done by default in VG.
                if (line.DiscountInPercent2 > 0)
                {
                    salesOrderComp.bcUpdateDouble((int)CustomerOrderLine_Properties.COL_DiscountII, (double)line.DiscountInPercent2);
                }

                #region Validera raden.
                if (artCode > 0 && artCode != 258 && artCode != 30202)
                {
                    // 258 får man vid registrering av artikelstrukturer.
                    // 30202 = Utgår. Ur hjälptexten: 'Du får registrera order på en artikel med status "Utgår" så länge som den disponibla behållningen är större än 0'
                    lineIsValid = false;
                    LogFileWriter.WriteLine(string.Format("ArticleNo '{0}' caused exception({1}): {2}", line.ArticleNo, artCode, salesOrderComp.bcGetMessageText(artCode)));
                }
                else if (priceCode > 0)
                {
                    lineIsValid = false;
                    LogFileWriter.WriteLine(string.Format("NetPrice '{0}' caused exception({1}): {2}", line.Price, priceCode, salesOrderComp.bcGetMessageText(priceCode)));
                }
                else if (qtyCode > 0 && qtyCode != 11944)                 // 11944 får man vid registrering av artikelstrukturer.
                {
                    lineIsValid = false;
                    LogFileWriter.WriteLine(string.Format("Quantity '{0}' caused exception({1}): {2}", line.Quantity, qtyCode, salesOrderComp.bcGetMessageText(qtyCode)));
                }
                #endregion

                #region Skapa felrapport eller spara raden.
                if (lineIsValid)
                {
                    errCode = salesOrderComp.bcChangeLine(salesOrderComp.bcGetNoOfLines() + 1);

                    if (errCode > 0)
                    {
                        LogFileWriter.WriteLine(string.Format("bcChangeLine caused exception: {0}", salesOrderComp.bcGetMessageText(errCode)));
                        allLinesCreated = false;
                        break;
                    }
                }
                else
                {
                    allLinesCreated = false;
                    salesOrderComp.bcDeleteLine(salesOrderComp.bcGetNoOfLines());
                }
                #endregion
            }

            #region Kontrollera att alla orderrader skapats.
            if (allLinesCreated)
            {
                if (_customerQuery.CustomerShouldPayPostage(transferItem.CustomerNo))
                {
                    var orderValue = (decimal)salesOrderComp.bcGetDouble((int)CustomerOrder_Properties.COR_TotalAmount);
                    var valueOfExcludedOrderlines = CalculateValueOfLinesThatShouldBeExcluded(transferItem);
                    orderValue = orderValue - valueOfExcludedOrderlines;

                    // Due to rounding order value can actually be less than zero if all lines ar excluded.
                    orderValue = Math.Max(orderValue, 0);

                    var postage = Math.Round((double)orderValue * (_postageCalculationParameters.PostagePercentage / 100));
                    salesOrderComp.bcUpdateDouble((int)CustomerOrder_Properties.COR_Postage, postage);
                }

                errCode = salesOrderComp.bcSaveAndFinish();

                if (errCode > 0)
                {
                    LogFileWriter.WriteLine("bcSaveAndFinish failed with message: " + salesOrderComp.bcGetMessageText(errCode));
                }

                DeleteEmptyOrderlines(salesOrderComp, transferItem.OrderNoInDestinationClient);
            }
            else
            {
                LogFileWriter.WriteLine(string.Format("At least one orderline failed. Calling CancelAndFinish for invoice {0}.", transferItem.InvoiceNo));

                salesOrderComp.bcCancelAndFinish();
                transferItem.OrderNoInDestinationClient = string.Empty;
            }
            #endregion

            return(transferItem.OrderNoInDestinationClient);
        }