public static CashReceiptDto GenerateCashReceipt(CashReceiptGenerationParameters parameters) { CashReceiptDto cashReceipt = new CashReceiptDto { procDate = parameters.EntryDate.AddDays(5), entryDate = parameters.EntryDate, note = "note_1", total = 50, detailCollection = new[] { "det_1", "det_2" }, customFields = new UserDefinedFieldValueDto[] { new UserDefinedFieldValueDto { userDefinedFieldId = parameters.UserDefinedFields[0].id, value = "field_1" }, new UserDefinedFieldValueDto { userDefinedFieldId = parameters.UserDefinedFields[1].id, value = "field_2" } } }; if (parameters.CustomerId.HasValue) { cashReceipt.customerId = parameters.CustomerId.Value; cashReceipt.discount = 10; } else { cashReceipt.acEntries = new AcEntryDto[] { new AcEntryDto { accountCode = parameters.AnalysisCategories[0].accountCode, analysisCategoryId = parameters.AnalysisCategories[0].id, value = 30m }, new AcEntryDto { accountCode = parameters.AnalysisCategories[1].accountCode, analysisCategoryId = parameters.AnalysisCategories[1].id, value = 20m } }; } return cashReceipt; }
private void UpdateSingleCashReceipt(CashReceiptDto cashReceipt) { ApiClientProvider.Default.CashReceipts.Update(cashReceipt.id, cashReceipt); Tracer.WriteLine("Single Cash Receipt with Id {0} was updated.", cashReceipt.id); Tracer.WriteLine(); }
private void ProcessCashReceiptBatch(CashReceiptDto[] source) { const int itemsToCreateCount = 2; const int itemsToUpdateCount = 2; const int itemsToDeleteCount = 2; List<BatchItem<CashReceiptDto>> batchCashReceipts = new List<BatchItem<CashReceiptDto>>(); // Prepare batch items to create. CashReceiptGenerationParameters parametersWithCustomer = GetParametersForSingleCashReceiptCreation(true); CashReceiptGenerationParameters parametersWithoutCustomer = GetParametersForSingleCashReceiptCreation(false); for (int i = 0; i < itemsToCreateCount; i++) { bool withCustomer = (i % 2 == 0); // True if index is even. CashReceiptGenerationParameters parameters = withCustomer ? parametersWithCustomer : parametersWithoutCustomer; batchCashReceipts.Add(new BatchItem<CashReceiptDto> { item = SampleDtoGenerator.GenerateCashReceipt(parameters), opCode = BatchOperationCodes.Create }); } int sourceIndex = 0; // Prepare batch items to update. for (int i = 0; i < itemsToUpdateCount; i++) { CashReceiptDto cashReceiptToUpdate = source[sourceIndex]; ModifyCashReceiptForUpdate(cashReceiptToUpdate); batchCashReceipts.Add(new BatchItem<CashReceiptDto> { item = cashReceiptToUpdate, opCode = BatchOperationCodes.Update }); sourceIndex++; } // Prepare batch items to delete. for (int i = 0; i < itemsToDeleteCount; i++) { batchCashReceipts.Add(new BatchItem<CashReceiptDto> { item = new CashReceiptDto { id = source[sourceIndex].id, timestamp = source[sourceIndex].timestamp }, opCode = BatchOperationCodes.Delete }); sourceIndex++; } // Execute batch operation. BatchItemProcessResult<CashReceiptDto>[] batchResult = ProcessBatch(batchCashReceipts.ToArray(), ApiClientProvider.Default.CashReceipts.ProcessBatch); // Display batch results. Tracer.WriteLine("Batch of Cash Receipts was processed:"); IEnumerable<long> createdItemsIds = batchResult.Take(itemsToCreateCount).Select(itemResult => itemResult.id); Tracer.WriteLine("{0} items were created. Ids: {1}.", itemsToCreateCount, String.Join(", ", createdItemsIds)); IEnumerable<long> updatedItemsIds = batchResult.Skip(itemsToCreateCount).Take(itemsToUpdateCount).Select(itemResult => itemResult.id); Tracer.WriteLine("{0} items were updated. Ids: {1}.", itemsToUpdateCount, String.Join(", ", updatedItemsIds)); IEnumerable<long> deletedItemsIds = batchResult.Skip(itemsToCreateCount + itemsToUpdateCount).Take(itemsToDeleteCount).Select(itemResult => itemResult.id); Tracer.WriteLine("{0} items were deleted. Ids: {1}.", itemsToDeleteCount, String.Join(", ", deletedItemsIds)); Tracer.WriteLine(); }
protected void ModifyCashReceiptForUpdate(CashReceiptDto cashReceipt) { cashReceipt.total = 70; if (cashReceipt.customerId.HasValue) { cashReceipt.discount = 20; } else { cashReceipt.acEntries.First().value = 50m; } }