private void CreateExpense(QuickBooksOnlineClient client, string txnDate, decimal amount, string account, string privateNote) { const int paymentAccountUndepositedFunds = 24; var expense = new Purchase { TxnDate = txnDate, PaymentType = "Cash", AccountRef = new Reference { Value = paymentAccountUndepositedFunds.ToString() }, Line = new List <PurchaseLine> { new PurchaseLine { DetailType = "AccountBasedExpenseLineDetail", Amount = amount, AccountBasedExpenseLineDetail = new AccountBasedExpenseLineDetail { TaxCodeRef = new Reference { Value = "NON" }, AccountRef = new Reference { Value = account }, BillableStatus = "NotBillable" } } }, PrivateNote = privateNote }; client.Create(expense); }
public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response, FinanceUser user) { var receipt = JsonConvert.DeserializeObject <Receipt>(request.Body); var dbClient = new AmazonDynamoDBClient(); var logger = new ConsoleLogger(); var receiptDbClient = new DatabaseClient <ReceiptSaveResult>(dbClient, logger); var spotReservationDbClient = new DatabaseClient <SpotReservation>(dbClient, logger); var vendorDbClient = new DatabaseClient <Vendor>(dbClient, logger); var qboClient = new QuickBooksOnlineClient(PrivateAccounting.Constants.LakelandMiPuebloRealmId, new DatabaseClient <QuickBooksOnlineConnection>(dbClient, logger), logger); var allActiveCustomers = qboClient .QueryAll <Customer>("select * from customer") .ToDictionary(x => x.Id); var activeVendors = new ActiveVendorSearch() .GetActiveVendors(allActiveCustomers, vendorDbClient) .ToList(); var spotClient = new DatabaseClient <Spot>(dbClient, logger); var spotReservationCheck = new SpotReservationCheck(spotClient, spotReservationDbClient, activeVendors, allActiveCustomers); var validation = new ReceiptValidation(spotReservationCheck).Validate(receipt).Result; if (validation.Any()) { response.StatusCode = 400; response.Body = new JObject { { "error", JArray.FromObject(validation) } }.ToString(); return; } var taxRate = new Tax().GetTaxRate(qboClient, PropertyRentalManagement.Constants.QUICKBOOKS_RENTAL_TAX_RATE); var cardPayment = new CardPayment(logger, Configuration.CLOVER_MI_PUEBLO_PRIVATE_TOKEN); var receiptService = new ReceiptSave(receiptDbClient, qboClient, taxRate, spotReservationDbClient, logger, cardPayment); string customerId = receipt.Customer.Id; if (string.IsNullOrWhiteSpace(customerId)) { var customer = new Customer { DisplayName = receipt.Customer.Name }; customer = qboClient.Create(customer); customerId = customer.Id.ToString(); } var vendor = activeVendors.FirstOrDefault(x => x.QuickBooksOnlineId.GetValueOrDefault().ToString() == customerId) ?? vendorDbClient.Create(VendorService.CreateModel(int.Parse(customerId), null, null, null)); receipt.Id = string.IsNullOrWhiteSpace(receipt.Id) ? Guid.NewGuid().ToString() : receipt.Id; // Needed until UI is deployed. var receiptResult = receiptService.SaveReceipt(receipt, customerId, user.FirstName, user.LastName, user.Email, vendor, IpLookup.GetIp(request)); response.Body = JsonConvert.SerializeObject(receiptResult); }
private void CreateSalesReceipt( QuickBooksOnlineClient client, int?customerId, string taxCode, int product, DateTime date, decimal amount, string memo) { var salesReceipt = new SalesReceipt { CustomerRef = new PropertyRentalManagement.QuickBooksOnline.Models.Reference { Value = customerId.ToString() }, TxnDate = date.ToString("yyyy-MM-dd"), TotalAmount = amount, PrivateNote = memo, Line = new List <SalesLine> { new SalesLine { Amount = amount, DetailType = "SalesItemLineDetail", SalesItemLineDetail = new SalesItemLineDetail { ItemRef = new PropertyRentalManagement.QuickBooksOnline.Models.Reference { Value = product.ToString() }, Quantity = 1, UnitPrice = amount, TaxCodeRef = new PropertyRentalManagement.QuickBooksOnline.Models.Reference { Value = Constants.QUICKBOOKS_INVOICE_LINE_TAXABLE } } } }, TxnTaxDetail = new TxnTaxDetail { TxnTaxCodeRef = new PropertyRentalManagement.QuickBooksOnline.Models.Reference { Value = taxCode } } }; client.Create(salesReceipt); }