示例#1
0
        private void FormateTransfer()
        {
            // Check for auctions in selected date
            var procuratories = DataBaseClient.ReadProcuratories(FormateDate);

            var supplierOrders = DataBaseClient.ReadSupplierOrders().Where(s => s.auction.siteid == 4 && s.auction.date == FormateDate && s.supplierid != 3 && s.supplierid != 27 && s.supplierid != 354 && s.supplierid != 384 && s.supplierid != 385).ToList();

            if (procuratories != null && procuratories.Count() > 0)
            {
                // Set folder for files
                try
                {
                    path = Service.GetDirectory().FullName;
                }
                catch { path = ""; }

                if (!string.IsNullOrEmpty(path))
                {
                    for (var iBroker = 1; iBroker <= 4; iBroker++)
                    {
                        // Get template & copy them
                        if (supplierOrders.Where(s => s.contract.brokerid == iBroker).Count() > 0)
                        {
                            templateFile = path + "\\" + "Перевод в КЦ по ТОО " + (iBroker == 1 ? "'Альта и К'" : iBroker == 2 ? "'Корунд-777'" : iBroker == 3 ? "'Альтаир-Нур'" : "'Ак Алтын Ко'") + " для даты аукциона " + FormateDate.ToShortDateString() + ".docx";

                            if (Service.CopyFile(templatePath + "MoneyTransfer.docx", templateFile, true))
                            {
                                // Convert EF to BO
                                List <MoneyTransferList> moneyTransferList = new List <MoneyTransferList>();

                                var supplierJournal = DataBaseClient.ReadSuppliersJournals();
                                List <ClearingCountingEF> clearingCountingLst = new List <ClearingCountingEF>();

                                foreach (var item in supplierOrders.Where(s => s.contract.brokerid == iBroker))
                                {
                                    foreach (var subItem in procuratories.Where(p => p.supplierid == item.supplierid && p.auctionid == item.auctionid))
                                    {
                                        try
                                        {
                                            moneyTransferList.Add(new MoneyTransferList()
                                            {
                                                fromCompany = iBroker == 1 ? "altaik" : iBroker == 2 ? "korund" : iBroker == 3 ? "alta008" : "akaltko",
                                                toCompany   = supplierJournal.FirstOrDefault(s => s.supplierid == item.supplierid && s.brokerid == iBroker).code,
                                                lotNumber   = subItem.lot.number,
                                                sum         = (subItem.lot.sum / 100 * Convert.ToDecimal(0.1)).ToString()
                                            });

                                            //
                                            clearingCountingLst.Add(new ClearingCountingEF()
                                            {
                                                brokerid       = iBroker,
                                                fromsupplierid = iBroker == 1 ? 354 : iBroker == 2 ? 354 : iBroker == 3 ? 27 : 384,
                                                tosupplierid   = (int)subItem.supplierid,
                                                lotid          = (int)subItem.lotid,
                                                transaction    = subItem.lot.sum / 100 * Convert.ToDecimal(0.1),
                                                createdate     = DateTime.Now,
                                                statusid       = 9
                                            });

                                            // Put records in base

                                            /*if(DataBaseClient.CreateClearingCounting(clearingCounting) == 0) {
                                             *  MessagesService.Show("Заявление об изменении денежных средств", "Произошла ошибка при занесении данных в базу");
                                             *  AppJournal.Write("MoneyTransfer", "Fault when create record in base", true);
                                             * }*/
                                        }
                                        catch { }
                                    }
                                }

                                // Save into data base
                                foreach (var item in clearingCountingLst)
                                {
                                    // Check for exist
                                    var searchItem = DataBaseClient.ReadClearingCounting(item.brokerid, item.fromsupplierid, item.tosupplierid, item.lotid);

                                    // Save if not or remove old and create new record
                                    if (searchItem != null)
                                    { // Update
                                        DataBaseClient.UpdateClearingCounting(item.id, item.transaction);
                                    }
                                    else
                                    { // New
                                        if (DataBaseClient.CreateClearingCounting(item) == 0)
                                        {
                                            MessagesService.Show("Заявление об изменении денежных средств", "Произошла ошибка при занесении данных в базу");
                                            AppJournal.Write("MoneyTransfer", "Fault when create record in base", true);
                                        }
                                    }
                                }
                                //

                                // Formate file
                                MoneyTransferService.CreateDocument(templateFile, (iBroker == 1 ? "ТОО 'Альта и К'" : iBroker == 2 ? "ТОО 'Корунд-777'" : iBroker == 3 ? "ТОО 'Альтаир-Нур'" : "ТОО 'Ак Алтын Ко'"), moneyTransferList);
                            }
                        }
                    }
                }

                // Open folder
                FolderExplorer.OpenFolder(path + "\\");

                /*// Get templates & copy to auction directory
                 * var docMoneyTransferReq = GetDocumentRequisites("Заявление в КЦ №" + Auction.number.Replace("/", "_") + " (c " + Order.Auction.SupplierOrders[0].BrokerCode + " на " + Order.Auction.SupplierOrders[0].Code + ").docx", DocumentTypeEnum.MoneyTransfer);
                 * var moneyTransferTemplateFile = archiveManager.GetTemplate(docMoneyTransferReq, DocumentTemplateEnum.MoneyTransfer);
                 *
                 * // Get transaction sum
                 * var transactionSum = Order.Auction.Lots[0].Sum / 100 * Convert.ToDecimal(0.1);
                 *
                 * // Formate money transfer document & open folder with new document
                 * if(MoneyTransferService.CreateDocument(Order, moneyTransferTemplateFile, transactionSum)) {
                 *  OpenFolder();
                 *
                 *  // Put records in base
                 *  ClearingCountingEF clearingCounting = new ClearingCountingEF() {
                 *      brokerid = (int)SelectedSupplierOrder.contract.brokerid,
                 *      fromsupplierid = DataBaseClient.ReadSupplier(SelectedSupplierOrder.contract.broker.companyId).id,
                 *      tosupplierid = (int)SelectedSupplierOrder.supplierid,
                 *      lotid = SelectedLot.id,
                 *      transaction = transactionSum,
                 *      createdate = DateTime.Now,
                 *      statusid = 9
                 *  };
                 *
                 *  if(DataBaseClient.CreateClearingCounting(clearingCounting) == 0) {
                 *      MessagesService.Show("Заявление об изменении денежных средств", "Произошла ошибка при занесении данных в базу");
                 *      AppJournal.Write("MoneyTransfer", "Fault when create record in base", true);
                 *  }
                 * } else MessagesService.Show("Заявление об изменении денежных средств", "Произошла ошибка при формировании заявления");*/
                //
            }
            else
            {
                MessagesService.Show("Оповещение", "На эту дату нет аукционов или не созданы поручения");
            }
        }