Exemplo n.º 1
0
        public void InitFromInvoice(SourceDocumentsSalesInvoicesInvoice invoice, string hashDocumentoAnterior)
        {
            if (invoice != null)
            {
                DocumentTypes       = new string[] { "FT", "FS", "FR", "ND", "NC", "VD", "TV", "TD", "AA", "DA", "RP", "RE", "CS", "LD", "RA" };
                DocumenType         = invoice.InvoiceType;
                DocumentTotal       = invoice.DocumentTotals.GrossTotal;
                DocumentDate        = invoice.InvoiceDate;
                SystemDate          = invoice.SystemEntryDate;
                PreviousHash        = hashDocumentoAnterior;
                CurrentDocumentHash = invoice.Hash;
                string[] invoiceNo = invoice.InvoiceNo.Split('/');
                if (invoiceNo != null && invoiceNo.Length == 2)
                {
                    int.TryParse(invoiceNo[1], out int num);
                    DocumentNumber = num;

                    string[] tipoSerie = invoiceNo[0].Split(' ');
                    if (tipoSerie != null && tipoSerie.Length == 2)
                    {
                        BillingNumber = tipoSerie[1];
                    }
                }

                ValuesFromDocument = true;
            }
        }
Exemplo n.º 2
0
        public void FillInvoices(DataSet ds)
        {
            string invoice="";
            invs.Clear();
            List<SourceDocumentsSalesInvoicesInvoiceLine> lines = new List<SourceDocumentsSalesInvoicesInvoiceLine>();
            SourceDocumentsSalesInvoicesInvoice i = new SourceDocumentsSalesInvoicesInvoice();
            int line=1;
            decimal nettotal=0;

            foreach (DataRow r in ds.Tables[0].Rows)
            {
                if (invoice != "FA " + r["invoiceno"].ToString().Replace(' ', '/'))
                {
                    if (invoice != "")
                    {
                        i.DocumentTotals = new SourceDocumentsSalesInvoicesInvoiceDocumentTotals();
                        i.DocumentTotals.TaxPayable = 0;
                        i.DocumentTotals.NetTotal = nettotal;
                        i.DocumentTotals.GrossTotal = nettotal;
                        i.Line = lines.ToArray();
                        lines.Clear();
                        line = 1;
                        nettotal = 0;
                    }

                    i = new SourceDocumentsSalesInvoicesInvoice();
                    invs.Add(i);
                    invoice = "FA "+r["invoiceno"].ToString().Replace(' ','/');
                    i.InvoiceNo = invoice;
                    i.InvoiceDate = (DateTime)r["invoicedate"];
                    i.SystemEntryDate = (DateTime)r["systemEntryDate"];
                    i.CustomerID = (string)r["customerid"];
                    i.Hash = "0";
                    i.SelfBillingIndicator = "0";
                }
                    SourceDocumentsSalesInvoicesInvoiceLine l = new SourceDocumentsSalesInvoicesInvoiceLine();
                    lines.Add(l);
                    l.LineNumber = (line++).ToString() ;
                    l.ProductCode = r["ProductCode"].ToString();
                    l.ProductDescription = (string)r["ProductDescription"];
                    l.Quantity = 1;
                    l.UnitOfMeasure = "Unidade";
                    l.UnitPrice = (decimal)r["UnitPrice"];
                    l.TaxPointDate = (DateTime)r["TaxPointDate"];
                    l.Description = l.ProductDescription;
                    l.Item = (decimal)r["CreditAmount"];
                    l.SettlementAmount = (decimal)r["Settlementamount"];
                    l.ItemElementName = ItemChoiceType2.CreditAmount;
                    l.Tax = new Tax();
                    l.Tax.TaxType = TaxType.IVA;
                    l.Tax.TaxCountryRegion = "PT";
                    l.Tax.TaxCode = "ISE";
                    l.Tax.Item = 0;
                    l.Tax.ItemElementName = ItemChoiceType3.TaxPercentage;
                    l.TaxExemptionReason = "Isento ao abrigo do art. 9º do CIVA";
                    nettotal += l.Item;

            }
            i.DocumentTotals = new SourceDocumentsSalesInvoicesInvoiceDocumentTotals();
            i.DocumentTotals.TaxPayable = 0;
            i.DocumentTotals.NetTotal = nettotal;
            i.DocumentTotals.GrossTotal = nettotal;
            i.Line = lines.ToArray();
        }