public string countCustomers(string serverName, string databaseName) { CompanyIdentifier companyIdentifier = session.LookupCompanyIdentifier(serverName, databaseName); connectionStatus = session.RequestAccess(companyIdentifier); Console.WriteLine("Result {0}", connectionStatus.ToString()); if (connectionStatus == AuthorizationResult.Granted) { Company company = session.Open(companyIdentifier); Console.WriteLine("Company {0}", company.CompanyIdentifier.CompanyName); var customers = company.Factories.CustomerFactory.List(); FilterExpression filter = FilterExpression.Equal( FilterExpression.Property("Customer.IsInactive"), FilterExpression.Constant(false)); LoadModifiers modifiers = LoadModifiers.Create(); modifiers.Filters = filter; customers.Load(modifiers); int count = customers.Count; session.Close(company); return("{\"count\":\"" + count + "\"}"); } return("{\"error\":\"Access: " + connectionStatus.ToString() + "\"}"); }
/// <summary> /// Return a string representation of this object. /// </summary> public override String ToString() { if (ProviderId != null) { return(String.Concat(AuthorizationResult.ToString(), ", ", ProviderId)); } return(String.Concat(AuthorizationResult.ToString())); }
public string getCustomers(string serverName, string databaseName, int page) { CompanyIdentifier companyIdentifier = session.LookupCompanyIdentifier(serverName, databaseName); connectionStatus = session.RequestAccess(companyIdentifier); Console.WriteLine("Result {0}", connectionStatus.ToString()); if (connectionStatus == AuthorizationResult.Granted) { Company company = session.Open(companyIdentifier); Console.WriteLine("Company {0}", company.CompanyIdentifier.CompanyName); var customers = company.Factories.CustomerFactory.List(); FilterExpression filter = FilterExpression.Equal( FilterExpression.Property("Customer.IsInactive"), FilterExpression.Constant(false)); LoadModifiers modifiers = LoadModifiers.Create(); modifiers.Filters = filter; customers.Load(modifiers); var cs = customers.ToList(); List <CustomerDetails> customerDetailsList = new List <CustomerDetails>(); int start_index = page * config.recordsPerPage; for (int index = start_index; index < start_index + config.recordsPerPage; index++) { if (index >= cs.Count) { break; } Customer customer = cs[index]; CustomerDetails customerDetails = new CustomerDetails(customer.ID) { AccountNumber = customer.AccountNumber, Balance = customer.Balance, Email = customer.Email, LastInvoiceAmount = customer.LastInvoiceAmount, Name = customer.Name, LastPaymentAmount = customer.LastPaymentAmount, PaymentMethod = customer.PaymentMethod, Category = customer.Category }; if (customer.AverageDaysToPayInvoices != null) { customerDetails.AverageDaysToPayInvoices = (decimal)customer.AverageDaysToPayInvoices; } customerDetails.PhoneNumbers = customer.PhoneNumbers; if (customer.CustomerSince != null) { customerDetails.CustomerSince = customer.CustomerSince.ToString(); } if (customer.LastPaymentDate != null) { customerDetails.LastPaymentDate = customer.LastPaymentDate.ToString(); } if (customer.LastStatementDate != null) { customerDetails.LastStatementDate = customer.LastStatementDate.ToString(); } if (customer.LastInvoiceDate != null) { customerDetails.LastInvoiceDate = customer.LastInvoiceDate.ToString(); } customerDetailsList.Add(customerDetails); } session.Close(company); var json = new JavaScriptSerializer().Serialize(customerDetailsList); return(json.ToString()); } return("{\"error\":\"Access: " + connectionStatus.ToString() + "\"}"); }
public string getCustomerReceipts(string serverName, string databaseName, string customerID, DateTime dateFrom, DateTime dateTo) { CompanyIdentifier companyIdentifier = session.LookupCompanyIdentifier(serverName, databaseName); connectionStatus = session.RequestAccess(companyIdentifier); if (connectionStatus == AuthorizationResult.Granted) { Company company = session.Open(companyIdentifier); var customers = company.Factories.CustomerFactory.List(); FilterExpression filter3 = FilterExpression.Equal( FilterExpression.Property("Customer.ID"), FilterExpression.Constant(customerID)); LoadModifiers modifiers3 = LoadModifiers.Create(); modifiers3.Filters = filter3; customers.Load(modifiers3); var cs = customers.ToList(); if (cs.Count == 0) { session.Close(company); return("{\"error\":\"Customer not found" + "\"}"); } Customer customer = cs[0]; EntityReference customer_key = customer.Key; var receipts = company.Factories.ReceiptFactory.List(); //var cpf = company.Factories.ReceiptInvoiceLineFactory.List(); FilterExpression filter_receipt = FilterExpression.Equal( FilterExpression.Property("Receipt.CustomerReference"), FilterExpression.Constant(customer_key)); LoadModifiers modifiers = LoadModifiers.Create(); modifiers.Filters = filter_receipt; receipts.Load(modifiers); //LoadModifiers modifiers2 = LoadModifiers.Create(); //modifiers.Filters = filter_receipt; //cpf.Load(); //List<Sage.Peachtree.API.ReceiptInvoiceLine> cpfList = cpf.ToList(); List <Sage.Peachtree.API.Receipt> receiptList = receipts.ToList(); List <ReceiptDetails> receiptDetailsList = new List <ReceiptDetails>(); for (int index = 0; index < receiptList.Count; index++) { Receipt receipt = receiptList[index]; ReceiptDetails ReceiptDetails = new ReceiptDetails((decimal)receipt.Amount) { PaymentMethod = receipt.PaymentMethod, ReferenceNumber = receipt.ReferenceNumber, Key = receipt.Key.Guid.ToString() }; if (receipt.Date != null) { ReceiptDetails.Date = receipt.Date.ToString(); } for (int x = 0; x < receipt.ApplyToInvoiceLines.Count; x++) { InvoiceLine Invoice = new InvoiceLine(receipt.ApplyToInvoiceLines[x].Amount, receipt.ApplyToInvoiceLines[x].AmountPaid) { Description = receipt.ApplyToInvoiceLines[x].Description, DiscountAmount = receipt.ApplyToInvoiceLines[x].DiscountAmount, InvoiceKey = receipt.ApplyToInvoiceLines[x].InvoiceReference.Guid.ToString() }; ReceiptDetails.ApplyToInvoices.Add(Invoice); } receiptDetailsList.Add(ReceiptDetails); } session.Close(company); var json = new JavaScriptSerializer().Serialize(receiptDetailsList); return(json.ToString()); } return("{\"error\":\"Access: " + connectionStatus.ToString() + "\"}"); }
public string getCustomerInvoices(string serverName, string databaseName, string customerID, DateTime dateFrom, DateTime dateTo) { CompanyIdentifier companyIdentifier = session.LookupCompanyIdentifier(serverName, databaseName); connectionStatus = session.RequestAccess(companyIdentifier); if (connectionStatus == AuthorizationResult.Granted) { Company company = session.Open(companyIdentifier); var customers = company.Factories.CustomerFactory.List(); FilterExpression filter2 = FilterExpression.Equal( FilterExpression.Property("Customer.ID"), FilterExpression.Constant(customerID)); LoadModifiers modifiers2 = LoadModifiers.Create(); modifiers2.Filters = filter2; customers.Load(modifiers2); var cs = customers.ToList(); if (cs.Count == 0) { session.Close(company); return("{\"error\":\"Customer not found" + "\"}"); } Customer customer = cs[0]; EntityReference customer_key = customer.Key; var invoices = company.Factories.SalesInvoiceFactory.List(); FilterExpression filter = FilterExpression.Equal( FilterExpression.Property("SalesInvoice.CustomerReference"), FilterExpression.Constant(customer_key)); LoadModifiers modifiers = LoadModifiers.Create(); modifiers.Filters = filter; invoices.Load(modifiers); List <Sage.Peachtree.API.SalesInvoice> invoicesList = invoices.ToList(); List <InvoiceDetails> invoiceDetailsList = new List <InvoiceDetails>(); for (int index = 0; index < invoicesList.Count; index++) { SalesInvoice invoice = invoicesList[index]; InvoiceDetails invoiceDetails = new InvoiceDetails((decimal)invoice.Amount, (decimal)invoice.AmountDue) { DiscountAmount = (decimal)invoice.DiscountAmount, ReferenceNumber = invoice.ReferenceNumber, Key = invoice.Key.Guid.ToString() }; if (invoice.Date != null) { invoiceDetails.Date = invoice.Date.ToString(); } if (invoice.DateDue != null) { invoiceDetails.DateDue = invoice.DateDue.ToString(); } if (invoice.DiscountDate != null) { invoiceDetails.DiscountDate = invoice.DiscountDate.ToString(); } invoiceDetailsList.Add(invoiceDetails); } session.Close(company); var json = new JavaScriptSerializer().Serialize(invoiceDetailsList); return(json.ToString()); } return("{\"error\":\"Access: " + connectionStatus.ToString() + "\"}"); }