public void SetUp()
        {
            this.fromAccount = MockRepository.GenerateMock <IAccount>();
            this.toAccount   = MockRepository.GenerateMock <IAccount>();

            this.fromAccount.Stub(x => x.Balance).PropertyBehavior();
            this.toAccount.Stub(x => x.Balance).PropertyBehavior();

            this.fromAccount.Balance = 100;
            this.toAccount.Balance   = 100;

            this.transactionScope   = MockRepository.GenerateMock <ITransactionScope>();
            this.transaction        = MockRepository.GenerateMock <ITransaction>();
            this.transactionManager = MockRepository.GenerateMock <ITransactionManager>();
            this.transactionManager.Stub(x => x.CreateScope()).Return(this.transactionScope);
            this.transactionManager.Stub(x => x.CurrentTransaction).Return(this.transaction);

            this.transferService = new MoneyTransferService(this.transactionManager);

            this.enlistedParticipants = new List <ITransactionParticipant>();
            this.transaction
            .Expect(x => x.EnlistVolatile(
                        Arg <ITransactionParticipant> .Is.Anything,
                        Arg <EnlistmentOptions> .Is.Anything))
            .Callback <ITransactionParticipant, EnlistmentOptions>(
                (x, y) =>
            {
                enlistedParticipants.Add(x);
                return(true);
            })
            .Return(MockRepository.GenerateStub <IEnlistment>())
            .Repeat.Any();
        }
예제 #2
0
        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);
            }
        }
예제 #3
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("Оповещение", "На эту дату нет аукционов или не созданы поручения");
            }
        }
        public void Constructor_throws_when_transactionManager_is_null()
        {
            var manager = new MoneyTransferService(null);

            Assert.Null(manager);
        }