/// <summary> /// takes a Xero Invoice, returns a Aquarium Invoice /// </summary> /// <param name="?"></param> public InboundInvoice(XeroApi.Model.Invoice theInboundXeroInvoice) { InboundInvoice theAquariumInvoiceToReturn = new InboundInvoice(); InvoicePDF = null; this.XeroInvoiceID_GUID = theInboundXeroInvoice.InvoiceID; //THESE FIELDS CAN ONLY BE GRABBED IF THE REFERENCE HAS BEEN PROPERLY RESOLVED if (theInboundXeroInvoice.InvoiceNumber.Contains('-')) { this.LeadID = InboundInvoice.GetLeadIDFromXeroInvoiceReferenceField(theInboundXeroInvoice);//from reference in Invoice this.MatterID = XeroHelper.GetMatterIDByLeadID(this.LeadID); this.LeadTypeID = XeroHelper.Aquarium_GetLeadTypeIDFromLeadID(LeadID); this.ProvidersInvoiceNumber = InboundInvoice.GetProviderInvoiceNumberFromXeroInvoiceNumberField(theInboundXeroInvoice); } this.InvoiceSubtotal = (decimal)theInboundXeroInvoice.SubTotal; this.InvoiceVATAmount = (decimal)theInboundXeroInvoice.TotalTax; this.InvoiceTotalCost = (decimal)theInboundXeroInvoice.Total; this.InvoiceDate = (DateTime)theInboundXeroInvoice.Date; if (theInboundXeroInvoice.LineItems.Count > 0) { if (theInboundXeroInvoice.LineItems.Count >= 1) { this.LineItem1Cost = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(0).UnitAmount.ToString()); this.LineItem1Desc = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(0).Description.ToString()); this.LineItem1Qty = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(0).Quantity.ToString()); } if (theInboundXeroInvoice.LineItems.Count >= 2) { this.LineItem2Cost = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(1).UnitAmount.ToString()); this.LineItem2Desc = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(1).Description.ToString()); this.LineItem2Qty = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(1).Quantity.ToString()); } if (theInboundXeroInvoice.LineItems.Count >= 3) { this.LineItem3Cost = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(2).UnitAmount.ToString()); this.LineItem3Desc = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(2).Description.ToString()); this.LineItem3Qty = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(2).Quantity.ToString()); } if (theInboundXeroInvoice.LineItems.Count >= 4) { this.LineItem4Cost = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(3).UnitAmount.ToString()); this.LineItem4Desc = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(3).Description.ToString()); this.LineItem4Qty = XeroHelper.ReturnStringifStringPassedIsZero(theInboundXeroInvoice.LineItems.ElementAtOrDefault(3).Quantity.ToString()); } } }
public bool Log(XeroApi.Model.Invoice anInvoice, InterResolveXeroService theService, LogCode Code) { //compose a line and write to file StreamWriter sw = new StreamWriter(); //success if(Code == LogCode.OK) { sw = File.AppendText(SuccessLogFileName + LogFilePath); } //fail else if (Code == LogCode.FAIL) { sw = File.AppendText(FailureLogFileName + LogFilePath); sw.WriteLine("Type:" + anInvoice.Type + "Company:" + theService.CompanyName + "Invoice Number:" + anInvoice.InvoiceNumber + " : " + "Ref:" + anInvoice.Reference + "Date:" + DateTime.Now + "NoOfErrors" + anInvoice.ValidationErrors.Count); } return true; }
/// <summary> /// converts a single IR line item invoice (e.g. one table Row) to a Xero Invoice /// </summary> /// <param name="anInvoiceToPost"></param> /// <returns></returns> public bool PostOutboundInvoiceToXero(XeroApi.Model.Invoice anInvoiceToPost) { try { //attempt a login this.LoginToXero(); //map the invoice posted to the Xero Invoice //call the post //write back the status to Aquarium return true; } catch (Exception ex) { throw ex; } }
private List<BalanceSheetEntry> ExtractSectionData(XeroApi.Model.ReportRow sectionRow, string sectionTitle, bool isAsset) { var balanceSheetEntries = new List<BalanceSheetEntry>(); foreach (var row in sectionRow.Rows.Where(r => r.RowType == "Row")) { var balanceSheetEntry = new BalanceSheetEntry(); balanceSheetEntry.isAsset = isAsset; balanceSheetEntry.Type = sectionTitle; balanceSheetEntry.Details = row.Cells[0].Value; balanceSheetEntry.AccountID = row.Cells[0].Attributes[0].Value; balanceSheetEntry.Amount = Convert.ToDecimal(row.Cells[1].Value); balanceSheetEntries.Add(balanceSheetEntry); } return balanceSheetEntries; }
private List<ProfitAndLossStatementEntry> ExtractPLSectionData(XeroApi.Model.ReportRow sectionRow, ProfitAndLossType type) { var profitAndLossEntries = new List<ProfitAndLossStatementEntry>(); foreach (var row in sectionRow.Rows.Where(r => r.RowType == "Row")) { var newEntry = new ProfitAndLossStatementEntry(); newEntry.ProfitAndLossType = type; newEntry.Details = row.Cells[0].Value; newEntry.AccountID = row.Cells[0].Attributes[0].Value; newEntry.Amount = Convert.ToDecimal(row.Cells[1].Value); profitAndLossEntries.Add(newEntry); } return profitAndLossEntries; }
/// <summary> /// Gets the TableRowID from a list of invoices /// </summary> /// <param name="theXeroInvoice"></param> /// <param name="theLineItemsToCheckAgainstAndRetriveTableRowIDFrom"></param> /// <returns></returns> public static Int64 GetTableRowIDfromXeroInvoice(XeroApi.Model.Invoice theXeroInvoice, OutboundInvoiceLineItemList theLineItemsToCheckAgainstAndRetriveTableRowIDFrom) { try { int InvoiceNumber = Convert.ToInt32(theXeroInvoice.InvoiceNumber); Int64 TableRowID = 0; for (int i = 0; i < theLineItemsToCheckAgainstAndRetriveTableRowIDFrom.OutboundInvoiceLineItems.Count; i++) { if (theLineItemsToCheckAgainstAndRetriveTableRowIDFrom.OutboundInvoiceLineItems.ElementAt(i).InvoiceNumber == InvoiceNumber) { TableRowID = theLineItemsToCheckAgainstAndRetriveTableRowIDFrom.OutboundInvoiceLineItems.ElementAt(i).TableRowID; break; } } return TableRowID; } catch(Exception ex) { throw ex;} }
public void GetXeroInvoicePDFByteArray(string theInvoiceGUID, XeroApi.Repository theRepository) { try { //to actually pull the pdf from Xero. //to assign it to this invoice's PDF container this.InvoicePDF = theRepository.FindById<Invoice>(theInvoiceGUID, XeroApi.MimeTypes.ApplicationPdf); } catch (Exception ex) { throw ex; } }
public void GetXeroInvoicePDFByteArray(XeroApi.Model.Invoice theInboundXeroInvoice, XeroApi.Repository theRepository) { try { //to get our GUID for the pdf System.Guid invoiceId = theInboundXeroInvoice.InvoiceID; //to hold the Guid //to actually pull the pdf from Xero. //to assign it to this invoice's PDF container this.InvoicePDF = theRepository.FindById<Invoice>(invoiceId.ToString(), XeroApi.MimeTypes.ApplicationPdf); } catch (Exception ex) { throw ex; } }
public static int GetProviderInvoiceNumberFromXeroInvoiceNumberField(XeroApi.Model.Invoice theInboundXeroInvoice) { int theProviderInvoiceNumber = 0; try { if (theInboundXeroInvoice.InvoiceNumber != null) { string[] temp = theInboundXeroInvoice.InvoiceNumber.ToString().Split('-'); theProviderInvoiceNumber = Convert.ToInt32(temp[0]); } return theProviderInvoiceNumber; } catch (Exception ex) { throw ex; } }
public static int GetLeadIDFromXeroInvoiceReferenceField(XeroApi.Model.Invoice theInboundXeroInvoice) { try { int LeadID = 0; string[] temp = null; if (theInboundXeroInvoice.InvoiceNumber != null && theInboundXeroInvoice.InvoiceNumber != "") { temp = theInboundXeroInvoice.InvoiceNumber.ToString().Split('-'); LeadID = Convert.ToInt32(temp[2]); } return LeadID; } catch (Exception ex) { throw ex; } }