public static void GenerateOrder(Order order) { archiveManager = new ArchiveManager(); orderInfo = order; var docReq = new DocumentRequisite() { fileName = "Заявка №" + order.Auction.Number.Replace("/", "_") + ".docx", date = order.Auction.Date, market = MarketPlaceEnum.UTB, number = order.Auction.Number, type = DocumentTypeEnum.Order, section = DocumentSectionEnum.Auction }; orderFileName = archiveManager.GetTemplate(docReq, DocumentTemplateEnum.Order); if (!string.IsNullOrEmpty(orderFileName)) { orderFileName = FillTemplateFile(); if (orderFileName != null) { docReq.fileName.Replace(".docx", ".pdf"); archiveManager.SaveFile(docReq, order.Auction.FilesListId); } } }
private void CreateBackMoneyTransfer() { // Log service AppJournal.Write("BackMoneyTransfer", "Create back money transfer documents", true); // Check for selected transaction if (SelectedClearingCount != null && SelectedClearingCount.statusid != 10) { // Get templates & copy to auction directory var fromCount = DataBaseClient.ReadSuppliersJournals(SelectedClearingCount.tosupplierid, SelectedClearingCount.brokerid); var toCount = DataBaseClient.ReadSuppliersJournals(SelectedClearingCount.fromsupplierid, SelectedClearingCount.brokerid); DocumentRequisite docMoneyTransferReq = new DocumentRequisite() { fileName = "Заявление на возврат из КЦ №" + SelectedClearingCount.lot.auction.number.Replace("/", "_") + " (c " + fromCount[0].code + " на " + toCount[0].code + ").docx", market = MarketPlaceEnum.ETS, date = SelectedClearingCount.lot.auction.date, number = SelectedClearingCount.lot.auction.number }; var moneyTransferTemplateFile = archiveManager.GetTemplate(docMoneyTransferReq, DocumentTemplateEnum.MoneyTransfer); // Fill order with needed data Order order = new Order(); order.Auction = new Auction(); order.Auction.SupplierOrders = new System.Collections.ObjectModel.ObservableCollection <SupplierOrder>(); order.Auction.SupplierOrders.Add(new SupplierOrder() { BrokerName = SelectedClearingCount.broker.name, BrokerCode = fromCount[0].code, Code = toCount[0].code }); order.Auction.Lots = new System.Collections.ObjectModel.ObservableCollection <Lot>(); order.Auction.Lots.Add(new Lot() { Number = SelectedClearingCount.lot.number }); // Formate money transfer document & open folder with new document if (MoneyTransferService.CreateDocument(order, moneyTransferTemplateFile, SelectedClearingCount.transaction)) { FolderExplorer.OpenAuctionFolder(MarketPlaceEnum.ETS, SelectedClearingCount.lot.auction.date.ToShortDateString(), SelectedClearingCount.lot.auction.number); // Put records in base ClearingCountingEF clearingCounting = new ClearingCountingEF() { brokerid = SelectedClearingCount.brokerid, fromsupplierid = fromCount[0].supplierid, tosupplierid = toCount[0].supplierid, lotid = SelectedClearingCount.lotid, transaction = SelectedClearingCount.transaction, createdate = DateTime.Now, statusid = 10 }; if (DataBaseClient.CreateClearingCounting(clearingCounting) == 0) { MessagesService.Show("Заявление об изменении денежных средств", "Произошла ошибка при занесении данных в базу"); AppJournal.Write("MoneyTransfer", "Fault when create record in base", true); } else { DataBaseClient.UpdateClearingCountStatus(toCount[0].supplierid, fromCount[0].supplierid, SelectedClearingCount.lotid); } Apply(0); } else { MessagesService.Show("Заявление об изменении денежных средств", "Произошла ошибка при формировании заявления"); } } else { MessagesService.Show("Заявление о возврате денежных средств", "Не выбрана транзакция или статус ОПЛАЧЕНО."); AppJournal.Write("BackMoneyTransfer", "Fault because not selected transaction or status payed.", true); } }
private void FormateContract() { // Prepare data // Get contract data var cContract = dataManager.ReadContracts(companyId, SelectedBroker != null ? SelectedBroker.id : 0); if (cContract == null || cContract.Count < 1) { MessagesService.Show("Формирование договора", "Нет данных договора"); return; } Contract caspyContract = cContract.FirstOrDefault(c => c.number.ToLower() == Contract.number); // Get company data var cCompany = dataManager.GetCompany(companyId); if (cCompany == null) { MessagesService.Show("Формирование договора", "Нет данных компании"); return; } Company caspyCompany = cCompany; caspyCompany.bank = Contract.bank != null ? Contract.bank.name : ""; caspyCompany.bik = Contract.bank != null ? Contract.bank.company.bik : ""; // Get company broker data var cBroker = dataManager.GetCompany(SelectedBroker.companyId); if (cBroker == null) { MessagesService.Show("Формирование договора", "Нет данных компании брокера"); return; } Company caspyBroker = cBroker; var bContracts = dataManager.ReadContracts(companyId, SelectedBroker.id); if (bContracts == null || bContracts.Count < 1) { MessagesService.Show("Формирование договора", "Нет данных договора брокера"); return; } var bContract = DataBaseClient.ReadContract(bContracts[0].id); if (bContract == null) { MessagesService.Show("Формирование договора", "Нет данных договора брокера"); return; } caspyBroker.bank = bContract.bank != null ? bContract.bank.name : ""; caspyBroker.bik = bContract.bank != null ? bContract.bank.company.bik : ""; // Copy templates to end folder DocumentRequisite docContractReq = new DocumentRequisite() { date = DateTime.Now, fileName = "Договор " + Contract.number + ".docx", number = Contract.company.bin, section = DocumentSectionEnum.Company, type = DocumentTypeEnum.Contract, market = MarketPlaceEnum.Caspy }; var contractFileName = archiveManager.GetTemplate(docContractReq, DocumentTemplateEnum.Contract); if (string.IsNullOrEmpty(contractFileName)) { MessagesService.Show("Формирование договора", "Ошибка копирования шаблона договора"); return; } string newFileName = FolderExplorer.GetCompanyPath(Contract.company.bin); newFileName += docContractReq.fileName; if (Service.CopyFile(contractFileName, newFileName, true)) { Service.DeleteFile(contractFileName); } else { MessagesService.Show("Формирование договора", "Ошибка копирования шаблона договора"); return; } if (string.IsNullOrEmpty(newFileName)) { MessagesService.Show("Формирование договора", "Ошибка копирования шаблона договора"); return; } // Fill contract template with prepared data if (!ContractService.FillKaspiContract(newFileName, caspyContract, caspyCompany, caspyBroker)) { MessagesService.Show("Формирование договора", "Произошла ошибка при формировании документа"); return; } DataBaseClient.UpdateContractFile(Contract.id, archiveManager.SaveFile(docContractReq)); }