Exemple #1
0
        /// <summary>
        /// Generate Invoice Xml File
        /// </summary>
        /// <param name="_templateName">Word template.dot file name</param>
        /// <param name="_invoiceNumber">Invoice number for generation</param>
        /// <returns>Xml file successfully written to XmlFolder</returns>
        private bool LoadInvoice(dbTradeControlDataContext context, string _templateName, string _invoiceNumber)
        {
            try
            {
                xsInvoiceTask invoiceTask = new xsInvoiceTask();
                invoiceTask.Clear();

                xsInvoiceTask.InvoiceRow invoiceTaskRow = invoiceTask.Invoice.NewInvoiceRow();

                vwDocCompany company = (from tb in context.vwDocCompanies
                                        select tb).FirstOrDefault();

                if (company != null)
                {
                    invoiceTaskRow.CompanyName         = company.CompanyName;
                    invoiceTaskRow.CompanyAddress      = company.CompanyAddress;
                    invoiceTaskRow.CompanyNumber       = company.CompanyNumber;
                    invoiceTaskRow.CompanyEmailAddress = company.CompanyEmailAddress;
                    invoiceTaskRow.CompanyWebsite      = company.CompanyWebsite;
                    invoiceTaskRow.CompanyPhoneNumber  = company.CompanyPhoneNumber;
                    invoiceTaskRow.CompanyNumber       = company.CompanyNumber;
                    invoiceTaskRow.CompanyVatNumber    = company.VatNumber;
                    invoiceTaskRow.BankAccountNumber   = company.BankAccountNumber;
                    invoiceTaskRow.BankAccount         = company.BankAccount;
                    invoiceTaskRow.BankSortCode        = company.BankSortCode;
                }

                vwDocInvoice invoice = (from tb in context.vwDocInvoices
                                        where tb.InvoiceNumber == _invoiceNumber
                                        select tb).First();

                documentFileName = $"{Repository}\\{invoice.AccountCode}_{_templateName}_{invoice.InvoiceNumber}";

                invoiceTaskRow.AccountCode = invoice.AccountCode;
                invoiceTaskRow.AccountName = invoice.AccountName;
                if (invoice.EmailAddress == null)
                {
                    invoiceTaskRow.EmailAddress = string.Empty;
                }
                else
                {
                    invoiceTaskRow.EmailAddress = invoice.EmailAddress;
                }

                emailAddress = invoice.EmailAddress;

                invoiceTaskRow.InvoiceNumber     = invoice.InvoiceNumber;
                invoiceTaskRow.InvoiceType       = invoice.InvoiceType;
                invoiceTaskRow.UserName          = invoice.UserName;
                invoiceTaskRow.InvoicedOn        = invoice.InvoicedOn;
                invoiceTaskRow.DueOn             = invoice.DueOn;
                invoiceTaskRow.Notes             = invoice.Notes ?? string.Empty;
                invoiceTaskRow.PaymentTerms      = invoice.PaymentTerms ?? string.Empty;
                invoiceTaskRow.InvoiceAddress    = invoice.InvoiceAddress;
                invoiceTaskRow.TotalInvoiceValue = invoice.InvoiceValue;
                invoiceTaskRow.TotalTaxValue     = invoice.TaxValue;
                invoiceTaskRow.InvoiceCharge     = invoice.InvoiceValue + invoice.TaxValue;

                invoiceTask.Invoice.AddInvoiceRow(invoiceTaskRow);

                //Add Invoice Items By Tasks >>>>
                var invoiceTasks = from tb in context.vwDocInvoiceTasks
                                   where tb.InvoiceNumber == _invoiceNumber
                                   orderby tb.ActionedOn
                                   select tb;

                foreach (vwDocInvoiceTask taskRow in invoiceTasks)
                {
                    xsInvoiceTask.InvoiceItemRow item = invoiceTask.InvoiceItem.NewInvoiceItemRow();
                    item.InvoiceNumber   = _invoiceNumber;
                    item.ActionedOn      = taskRow.ActionedOn.Value;
                    item.ActivityCode    = taskRow.ActivityCode;
                    item.CashCode        = taskRow.CashCode;
                    item.CashDescription = taskRow.CashDescription;
                    item.ItemDescription = taskRow.TaskTitle ?? string.Empty;
                    item.TaskCode        = taskRow.TaskCode;
                    item.SecondReference = taskRow.SecondReference ?? string.Empty;
                    item.TaxCode         = taskRow.TaxCode;
                    item.UnitOfMeasure   = taskRow.UnitOfMeasure;

                    item.UnitValue = taskRow.InvoiceValue / (decimal)taskRow.Quantity;
                    item.Quantity  = taskRow.Quantity;

                    item.InvoiceValue = taskRow.InvoiceValue;
                    item.TaxValue     = taskRow.TaxValue;
                    item.ItemCharge   = taskRow.InvoiceValue + taskRow.TaxValue;;
                    invoiceTask.InvoiceItem.AddInvoiceItemRow(item);
                }

                var invoiceItems = from tb in context.vwDocInvoiceItems
                                   where tb.InvoiceNumber == _invoiceNumber
                                   select tb;

                foreach (vwDocInvoiceItem itemRow in invoiceItems)
                {
                    xsInvoiceTask.InvoiceItemRow item = invoiceTask.InvoiceItem.NewInvoiceItemRow();
                    item.InvoiceNumber   = _invoiceNumber;
                    item.ActionedOn      = itemRow.ActionedOn;
                    item.ActivityCode    = string.Empty;
                    item.CashCode        = itemRow.CashCode;
                    item.CashDescription = itemRow.CashDescription;
                    item.ItemDescription = itemRow.ItemReference ?? string.Empty;
                    item.TaskCode        = string.Empty;
                    item.SecondReference = string.Empty;
                    item.TaxCode         = itemRow.TaxCode;
                    item.UnitOfMeasure   = string.Empty;

                    item.UnitValue = 0;
                    item.Quantity  = 0;

                    item.InvoiceValue = itemRow.InvoiceValue;
                    item.TaxValue     = itemRow.TaxValue;
                    item.ItemCharge   = itemRow.InvoiceValue + itemRow.TaxValue;;

                    invoiceTask.InvoiceItem.AddInvoiceItemRow(item);
                }

                var invoiceTax = from tb in context.vwTaxSummaries
                                 where tb.InvoiceNumber == _invoiceNumber
                                 orderby tb.TaxCode
                                 select tb;

                foreach (vwTaxSummary taxRow in invoiceTax)
                {
                    xsInvoiceTask.InvoiceVatRow taxCode = invoiceTask.InvoiceVat.NewInvoiceVatRow();
                    taxCode.InvoiceNumber     = _invoiceNumber;
                    taxCode.InvoiceValueTotal = (decimal)taxRow.InvoiceValueTotal;
                    taxCode.VatTaxCode        = taxRow.TaxCode;
                    taxCode.VatTaxRate        = (decimal)taxRow.TaxRate;
                    taxCode.TaxValueTotal     = (decimal)taxRow.TaxValueTotal;

                    invoiceTask.InvoiceVat.AddInvoiceVatRow(taxCode);
                }

                invoiceTask.WriteXml(Schema.InvoiceTaskXmlFileName);

                return(true);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, $"{err.Source}.{err.TargetSite.Name}", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// Generate Task Xml File for orders/quotes
        /// </summary>
        /// <param name="_templateName">Word template.dot file name</param>
        /// <param name="_taskCode">Task code for generation</param>
        /// <param name="_includeQuotedAttributes">Include attributes where state is set to quoted only</param>
        /// <returns>Xml file successfully written to XmlFolder</returns>
        private bool LoadTask(dbTradeControlDataContext context, string _templateName, string _taskCode, bool _includeQuotedAttributes)
        {
            try
            {
                xsTaskCode taskXml = new xsTaskCode();
                taskXml.Clear();
                xsTaskCode.TaskRow taskRow = taskXml.Task.NewTaskRow();

                vwDocCompany company = (from tb in context.vwDocCompanies
                                        select tb).FirstOrDefault();

                if (company != null)
                {
                    taskRow.CompanyName         = company.CompanyName;
                    taskRow.CompanyAddress      = company.CompanyAddress;
                    taskRow.CompanyNumber       = company.CompanyNumber;
                    taskRow.CompanyEmailAddress = company.CompanyEmailAddress;
                    taskRow.CompanyWebsite      = company.CompanyWebsite;
                    taskRow.CompanyPhoneNumber  = company.CompanyPhoneNumber;
                    taskRow.CompanyNumber       = company.CompanyNumber;
                    taskRow.CompanyVatNumber    = company.VatNumber;
                }

                vwDocTaskCode task = (from tb in context.vwDocTaskCodes
                                      where tb.TaskCode == _taskCode
                                      select tb).First();

                documentFileName = $"{Repository}\\{task.AccountCode}_{_templateName}_{task.TaskCode}";

                if (task.EmailAddress == null)
                {
                    taskRow.EmailAddress = string.Empty;
                }
                else
                {
                    taskRow.EmailAddress = task.EmailAddress;
                }

                emailAddress = taskRow.EmailAddress;

                taskRow.TaskCode        = task.TaskCode;
                taskRow.SecondReference = task.SecondReference;
                taskRow.PaymentTerms    = task.PaymentTerms;
                taskRow.TaskStatus      = task.TaskStatus;
                taskRow.TaskStatusCode  = task.TaskStatusCode;
                taskRow.TaskNotes       = task.TaskNotes;
                taskRow.TaskTitle       = task.TaskTitle;
                taskRow.TaxCode         = task.TaxCode;
                taskRow.TaxRate         = (decimal)task.TaxRate;
                taskRow.TotalCharge     = task.TotalCharge;
                taskRow.UnitCharge      = task.UnitCharge;
                taskRow.UnitOfMeasure   = task.UnitOfMeasure;
                taskRow.ContactName     = task.ContactName;
                taskRow.UserName        = task.UserName;
                taskRow.AccountCode     = task.AccountCode;
                taskRow.AccountName     = task.AccountName;
                taskRow.NickName        = task.NickName;
                taskRow.InvoiceAddress  = task.InvoiceAddress;
                taskRow.ActionOn        = task.ActionOn;
                taskRow.Quantity        = task.Quantity;

                taskRow.TaxCharge             = (double)task.TotalCharge * (double)task.TaxRate;
                taskRow.CollectionAddress     = task.CollectionAddress;
                taskRow.DeliveryAddress       = task.DeliveryAddress;
                taskRow.CollectionAccountName = task.CollectionAccountName;
                taskRow.DeliveryAccountName   = task.DeliveryAccountName;

                taskXml.Task.AddTaskRow(taskRow);

                var attributes = from tb in context.tbAttributes
                                 where tb.TaskCode == _taskCode
                                 orderby tb.PrintOrder
                                 select tb;

                foreach (tbAttribute attribute in attributes)
                {
                    if (_includeQuotedAttributes || attribute.AttributeTypeCode == (short)AttributeType.Order)
                    {
                        xsTaskCode.AttributesRow attribRow = taskXml.Attributes.NewAttributesRow();
                        attribRow.Attribute            = attribute.Attribute;
                        attribRow.AttributeDescription = attribute.AttributeDescription;
                        attribRow.AttributeTypeCode    = attribute.AttributeTypeCode;
                        taskXml.Attributes.AddAttributesRow(attribRow);
                    }
                }

                var quotes = from tb in context.tbQuotes
                             where tb.TaskCode == _taskCode
                             orderby tb.Quantity
                             select tb;

                foreach (tbQuote quote in quotes)
                {
                    xsTaskCode.QuotedPricesRow priceRow = taskXml.QuotedPrices.NewQuotedPricesRow();
                    priceRow.QuoteQuantity   = quote.Quantity;
                    priceRow.RunBackPrice    = quote.RunBackPrice;
                    priceRow.RunBackQuantity = quote.RunBackQuantity;
                    priceRow.RunOnPrice      = quote.RunOnPrice;
                    priceRow.RunOnQuantity   = quote.RunOnQuantity;
                    priceRow.QuotePrice      = quote.TotalPrice;
                    taskXml.QuotedPrices.AddQuotedPricesRow(priceRow);
                }

                var schedule = from tb in context.proc_Op(_taskCode)
                               orderby tb.OperationNumber
                               select tb;

                foreach (proc_OpResult op in schedule)
                {
                    xsTaskCode.ScheduleRow opRow = taskXml.Schedule.NewScheduleRow();
                    opRow.Duration        = (decimal)op.Duration;
                    opRow.EndOn           = op.EndOn;
                    opRow.Note            = op.Note;
                    opRow.Operation       = op.Operation;
                    opRow.OperationNumber = op.OperationNumber;
                    opRow.StartOn         = op.StartOn;
                    taskXml.Schedule.AddScheduleRow(opRow);
                }

                taskXml.WriteXml(Schema.TaskSingleXmlFileName);

                return(true);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, $"{err.Source}.{err.TargetSite.Name}", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }