Пример #1
0
        public IEnumerable <FieldResult> Aggregate(InvoiceTemplate template, InvoiceField field, IEnumerable <FieldResult> results)
        {
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            if (field?.Key == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if (results == null)
            {
                throw new ArgumentNullException(nameof(results));
            }

            var allItems = results.ToArray();

            if (allItems.Length > 0)
            {
                foreach (var item in allItems)
                {
                    if (!GetValue(template, item, out var date))
                    {
                        continue;
                    }

                    yield return(new FieldResult(field.Key, date.ToShortDateString()));

                    break;
                }
            }
        }
Пример #2
0
        public IHttpActionResult PutInvoiceTemplate(int id, InvoiceTemplate invoiceTemplate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != invoiceTemplate.MerchantId)
            {
                return(BadRequest());
            }

            db.Entry(invoiceTemplate).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InvoiceTemplateExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public InvoiceTemplates getInvoiceTemplates()
        {
            var apiContext = GetApiContext();
            var Invoices   = InvoiceTemplate.GetAll(apiContext);

            return(Invoices);
        }
Пример #4
0
        private IEnumerable <FieldResult> ProcessField(InvoiceTemplate template, Document document, InvoiceField field)
        {
            var result = extractor.Extract(field, document).ToArray();

            foreach (var aggregator in aggregators)
            {
                if (!aggregator.CanHandle(field))
                {
                    continue;
                }

                IEnumerable <FieldResult> aggregated = aggregator.Aggregate(template, field, result);
                foreach (FieldResult item in aggregated)
                {
                    yield return(item);
                }

                yield break;
            }

            foreach (var fieldResult in result)
            {
                yield return(fieldResult);
            }
        }
Пример #5
0
        public IEnumerable <FieldResult> Construct(InvoiceTemplate template, Document document)
        {
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            if (!string.IsNullOrEmpty(template.Issuer))
            {
                yield return(new FieldResult("issuer", template.Issuer));
            }
            else if (template.Keywords != null &&
                     template.Keywords.Length > 0)
            {
                yield return(new FieldResult("issuer", template.Keywords[0]));
            }

            foreach (InvoiceField field in template.Fields)
            {
                foreach (var result in ProcessField(template, document, field))
                {
                    yield return(result);
                }
            }
        }
Пример #6
0
 public void Setup()
 {
     _databaseSetup = new DatabaseSetup();
     _databaseSetup.CleanDatabase();
     _databaseSetup.CreateStandardDatabase();
     _invoiceTemplate = new InvoiceTemplate();
     _templateService = new TemplateService(_databaseSetup.GetTrexConnection);
 }
        private async void CreateCorrectionPDF_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var invoice = ViewModel.GetInvoice();

            if (invoice != null)
            {
                var invoiceTemplate = new InvoiceTemplate(invoice);

                try
                {
                    Utility.InvoiceTemplateStruct templateOriginal = new Utility.InvoiceTemplateStruct
                    {
                        CommentsCheckBox      = CommentsCheckBox.IsChecked == true,
                        InvoicePersonCheckBox = InvoicePersonCheckBox.IsChecked == true,
                        PickupPersonCheckBox  = PickupPersonCheckBox.IsChecked == true,
                        InvoiceTitle          = Utility.InvoiceTypeTemplateEnum.Correction,
                        InvoiceType           = Utility.InvoiceTypeTemplateEnum.Original
                    };
                    Utility.InvoiceTemplateStruct templateCopy = new Utility.InvoiceTemplateStruct
                    {
                        CommentsCheckBox      = CommentsCheckBox.IsChecked == true,
                        InvoicePersonCheckBox = InvoicePersonCheckBox.IsChecked == true,
                        PickupPersonCheckBox  = PickupPersonCheckBox.IsChecked == true,
                        InvoiceTitle          = Utility.InvoiceTypeTemplateEnum.Correction,
                        InvoiceType           = Utility.InvoiceTypeTemplateEnum.Copy
                    };

                    var pdfFile = invoiceTemplate.CreatePdf(templateOriginal);
                    invoiceTemplate.CreatePdf(templateCopy);

                    if (pdfFile != null)
                    {
                        var filePath = AppDomain.CurrentDomain.BaseDirectory + pdfFile;
                        var pdf      = new Uri(filePath, UriKind.RelativeOrAbsolute);

                        var process = new Process
                        {
                            StartInfo = new ProcessStartInfo(@pdf.AbsolutePath)
                            {
                                CreateNoWindow  = true,
                                UseShellExecute = true
                            }
                        };
                        process.Start();
                    }
                }
                catch (Exception)
                {
                    await Forge.Forms.Show.Dialog("InvoiceDialogHost").For(
                        new Information("Nie udało się utworzyć pliku PDF, " +
                                        "prawdopodobnie plik PDF jest otwarty w innym oknie, " +
                                        "zamknij pozostałe okna i spróbuj ponownie", "Zaznacz produkt", "OK"));
                }
            }
        }
Пример #8
0
 public void DeleteInvoiceTemplate(InvoiceTemplate template)
 {
     try
     {
         _templateService.DeleteTemplate(template);
     }
     catch (Exception ex)
     {
         LogError(ex);
     }
 }
        private void ExecuteCreateNewTemplate(object obj)
        {
            var invoiceTemplate = new InvoiceTemplate
            {
                CreateDate   = DateTime.Now,
                CreatedBy    = UserContext.Instance.User.Name,
                TemplateName = "No name"
            };

            _dataService.SaveInvoiceTemplate(invoiceTemplate).Subscribe(i => LoadTemplates());
        }
Пример #10
0
        public IHttpActionResult GetInvoiceTemplate(int id)
        {
            InvoiceTemplate invoiceTemplate = db.InvoiceTemplates.Find(id);

            if (invoiceTemplate == null)
            {
                return(NotFound());
            }

            return(Ok(invoiceTemplate));
        }
Пример #11
0
 public TemplateExtractor(ILogger <TemplateExtractor> logger, InvoiceTemplate template, IPreparationStepsFactory preparation, IFieldProcessor processor)
 {
     this.template    = template ?? throw new ArgumentNullException(nameof(template));
     this.preparation = preparation ?? throw new ArgumentNullException(nameof(preparation));
     this.processor   = processor ?? throw new ArgumentNullException(nameof(processor));
     this.logger      = logger ?? throw new ArgumentNullException(nameof(logger));
     if (!template.Validate())
     {
         throw new ArgumentOutOfRangeException(nameof(template));
     }
 }
Пример #12
0
        private void ExecuteCreateNewInvoiceTemplateStart(object obj)
        {
            var invoiceTemplate = new InvoiceTemplate
            {
                CreateDate = DateTime.Now,
                CreatedBy  = _userSession.CurrentUser.Name
            };

            var editInvoiceTemplateView = new EditInvoiceTemplateView();

            editInvoiceTemplateView.Show();
        }
Пример #13
0
        public IHttpActionResult PostInvoiceTemplate(InvoiceTemplate invoiceTemplate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.InvoiceTemplates.Add(invoiceTemplate);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = invoiceTemplate.MerchantId }, invoiceTemplate));
        }
Пример #14
0
        public string GenerateInvoiceNumber()
        {
            InvoiceTemplate itemplate = getTemplate();

            if (itemplate == null)
            {
                throw new Exception("Nie znaleziono wzoru");
            }
            template = itemplate.Template;
            replaceDate();
            replaceNumber();
            return(template);
        }
Пример #15
0
        public IHttpActionResult DeleteInvoiceTemplate(int id)
        {
            InvoiceTemplate invoiceTemplate = db.InvoiceTemplates.Find(id);

            if (invoiceTemplate == null)
            {
                return(NotFound());
            }

            db.InvoiceTemplates.Remove(invoiceTemplate);
            db.SaveChanges();

            return(Ok(invoiceTemplate));
        }
Пример #16
0
 public bool ValidateTemplate(InvoiceTemplate template)
 {
     try
     {
         ConvertBinaryToDocument(template.TemplateId);
         return(true);
     }
     catch (IOException ex)
     {
         const string message = "Template is properly open. Close it and run the action again";
         LogError(ex);
         LogMessage(message);
         throw new IOException(message);
     }
 }
Пример #17
0
        public IEnumerable <FieldResult> Aggregate(InvoiceTemplate template, InvoiceField field, IEnumerable <FieldResult> results)
        {
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            if (field?.Key == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if (results == null)
            {
                throw new ArgumentNullException(nameof(results));
            }

            double value    = 0;
            var    allItems = results.ToArray();
            bool   found    = false;

            if (allItems.Length > 0)
            {
                if (field.Key.StartsWith("sum_amount", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (var item in allItems)
                    {
                        if (GetValue(template, item, out var calculated))
                        {
                            value += calculated;
                            found  = true;
                        }
                    }
                }
                else
                {
                    if (GetValue(template, allItems[0], out value))
                    {
                        found = true;
                    }
                }
            }

            if (found)
            {
                yield return(new FieldResult(field.Key, value.ToString(CultureInfo.CurrentCulture)));
            }
        }
Пример #18
0
        public override void TemplateValidation(int invoiceId, IGatherData gatherData, int format)
        {
            try
            {
                var template = gatherData.GetCustomerInvoiceGroupsTemplateData(invoiceId, format);

                var invoiceTemplate = new InvoiceTemplate();
                if (format == 4 || format == 3)
                {
                    if (template.CreditNoteTemplateIdMail == null)
                    {
                        throw new CreditNoteTemplateIdNotSet();
                    }

                    invoiceTemplate = gatherData.GetInvoiceTemplate((int)template.CreditNoteTemplateIdMail);
                }

                if (format == 5 || format == 3)
                {
                    if (template.CreditNoteTemplateIdPrint == null)
                    {
                        throw new CreditNoteTemplateIdNotSet();
                    }

                    invoiceTemplate = gatherData.GetInvoiceTemplate((int)template.CreditNoteTemplateIdPrint);
                }

                var invoiceTemplateFound = gatherData.ValidateTemplate(invoiceTemplate);
                if (!invoiceTemplateFound)
                {
                    throw new FileNotFoundException("The invoice template could not be found");
                }
            }
            catch (Aspose.Words.UnsupportedFileFormatException ex)
            {
                LogError(ex);
                throw;
            }
            catch (Exception ex)
            {
                LogError(ex);
                throw;
            }
        }
Пример #19
0
        public Invoice SendInvoice(string email, string reference, string totalamount, string currency)
        {
            var apiContext      = GetApiContext();
            var TemplateInvoice = InvoiceTemplate.Get(apiContext, "TEMP-7V015177YY181050W");
            var TemplateInfo    = TemplateInvoice.template_data;

            var item    = TemplateInfo.items;
            var invoice = new Invoice
            {
                merchant_info = TemplateInfo.merchant_info,
                billing_info  = new List <BillingInfo>
                {
                    new BillingInfo
                    {
                        email = email
                    },
                },
                items = new List <InvoiceItem>
                {
                    new InvoiceItem {
                        name       = "Digital Goods",
                        quantity   = 1,
                        unit_price = new Currency
                        {
                            currency = currency, value = totalamount,
                        },
                        tax = new Tax
                        {
                            name    = "Service fees",
                            percent = (float)5.85
                        },
                    },
                },
                logo_url    = TemplateInfo.logo_url,
                terms       = TemplateInfo.terms,
                reference   = reference,
                note        = TemplateInfo.note,
                template_id = TemplateInvoice.template_id
            };
            var createdInvoice = invoice.Create(GetApiContext());

            createdInvoice.Send(GetApiContext());
            return(createdInvoice);
        }
Пример #20
0
        private bool GetValue(InvoiceTemplate template, FieldResult result, out double parsed)
        {
            var separator = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
            var text      = result.Value;

            if (!string.IsNullOrEmpty(template?.Options.DecimalSeparator) &&
                template.Options.DecimalSeparator != separator)
            {
                text = text.Replace(template.Options.DecimalSeparator, separator);
            }

            if (double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out parsed))
            {
                return(true);
            }

            logger.LogWarning("Failed parsing {0}", result.Value);
            return(false);
        }
        public IEnumerable <IPreparationStep> Construct(InvoiceTemplate template)
        {
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            if (template.Options.IsLowercase)
            {
                yield return(lowerCase);
            }

            if (template.Options.RemoveWhitespaces)
            {
                yield return(removeWhiteSpaces);
            }

            if (template.Options.RemoveAccents)
            {
                yield return(removeAccents);
            }

            if (template.Options.Replace == null)
            {
                yield break;
            }

            foreach (var pair in template.Options.Replace)
            {
                if (pair.Length == 2)
                {
                    yield return(new ReplaceStep(pair[0], pair[1]));
                }
                else
                {
                    logger.LogWarning("Failed parsing replace for {0}", template);
                }
            }
        }
Пример #22
0
        public void DeleteTemplate(InvoiceTemplate template)
        {
            try
            {
                var templateFiles = _entityContext.InvoiceTemplateFiles.Where(x => x.InvoiceTemplateId == template.TemplateId);

                foreach (var itf in templateFiles)
                {
                    _entityContext.InvoiceTemplateFiles.Attach(itf);
                    _entityContext.InvoiceTemplateFiles.DeleteObject(itf);
                }
                _entityContext.SaveChanges();

                _entityContext.InvoiceTemplates.Attach(template);
                _entityContext.InvoiceTemplates.DeleteObject(template);
                _entityContext.SaveChanges();
            }
            catch (Exception ex)
            {
                LogError(ex);
                throw;
            }
        }
Пример #23
0
        private bool GetValue(InvoiceTemplate template, FieldResult result, out DateTime parsed)
        {
            parsed = DateTime.MinValue;
            if (template.Options.DateFormats == null)
            {
                if (DateTime.TryParse(result.Value, out parsed))
                {
                    return(true);
                }
            }
            else
            {
                foreach (var format in template.Options.DateFormats)
                {
                    if (DateTime.TryParseExact(result.Value, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out parsed))
                    {
                        return(true);
                    }
                }
            }

            logger.LogWarning("Failed parsing {0}", result.Value);
            return(false);
        }
Пример #24
0
 public ITemplateExtractor Create(InvoiceTemplate template)
 {
     return(new TemplateExtractor(factory.CreateLogger <TemplateExtractor>(), template, preparation, processor));
 }
Пример #25
0
 public IObservable <Unit> SaveInvoiceTemplate(InvoiceTemplate invoiceTemplate)
 {
     return(_saveInvoiceTemplate(invoiceTemplate).ObserveOnDispatcher());
 }
        protected override void RunSample()
        {
            // ### Api Context
            // Pass in a `APIContext` object to authenticate
            // the call and to send a unique request id
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly.
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = Configuration.GetAPIContext();

            var invoiceTemplate = new InvoiceTemplate()
            {
                name            = "Template " + Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 8),
                @default        = true,
                unit_of_measure = "HOURS",
                template_data   = new InvoiceTemplateData()
                {
                    items = new List <InvoiceItem>()
                    {
                        new InvoiceItem()
                        {
                            name       = "Nutri Bullet",
                            quantity   = 1.0F,
                            unit_price = new Currency()
                            {
                                currency = "USD",
                                value    = "50.00"
                            }
                        }
                    },
                    merchant_info = new MerchantInfo()
                    {
                        email = "*****@*****.**"
                    },
                    tax_calculated_after_discount = false,
                    tax_inclusive = false,
                    note          = "Thank you for your business",
                    logo_url      = "https://pics.paypal.com/v1/images/redDot.jpeg",
                },
                settings = new List <InvoiceTemplateSettings>()
                {
                    new InvoiceTemplateSettings()
                    {
                        field_name         = "items.date",
                        display_preference = new InvoiceTemplateSettingsMetadata()
                        {
                            hidden = true
                        }
                    },
                    new InvoiceTemplateSettings()
                    {
                        field_name         = "custom",
                        display_preference = new InvoiceTemplateSettingsMetadata()
                        {
                            hidden = true
                        }
                    }
                }
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Create the template.", invoiceTemplate);
            #endregion

            // Create the invoice template
            var createdTemplate = invoiceTemplate.Create(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(createdTemplate);
            #endregion

            // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/).
        }
Пример #27
0
 public IObservable <Unit> DeleteInvoiceTemplate(InvoiceTemplate selectedTemplate)
 {
     return(_deleteInvoiceTemplate(selectedTemplate));
 }
Пример #28
0
 public void SetUp()
 {
     instance = CreateInstance();
 }
Пример #29
0
 public void SetUp()
 {
     template   = new InvoiceTemplate();
     mockLogger = new NullLogger <DateFieldAggregator>();
     instance   = CreateInstance();
 }
Пример #30
0
 public ExtractionResult(Document document, InvoiceTemplate template, FieldResult[] fields)
 {
     Template = template ?? throw new ArgumentNullException(nameof(template));
     Fields   = fields ?? throw new ArgumentNullException(nameof(fields));
     Document = document ?? throw new ArgumentNullException(nameof(document));
 }