private void SetStores(Data.StoreOrder storeOrder, Data.BaseInfo repository, Data.Goody goody, Data.Com company, Data.PriceList priceList) { try { switch (this.FormMode) { case Common.Enum.FormMode.New: SetStoresForNew(storeOrder, repository, goody, company, priceList); break; case Common.Enum.FormMode.Edit: SetStoresForEdit(storeOrder, repository, goody, company, priceList); break; default: break; } if (storeOrder.OId == null) { storeOrder.OId = Business.GetStoreOrderBusiness().GetMaxOIdByRepository(repository); Business.GetStoreOrderBusiness().SubmitChanges(); } } catch { throw; } }
private void SetStoresForEdit(Data.StoreOrder storeOrder, Data.BaseInfo repository, Data.Goody goody, Data.Com company, Data.PriceList priceList) { try { using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted, Timeout = new TimeSpan(2, 0, 0) })) { var storeDetails = Business.GetStoreOrderDetailBusiness().GetByStoreOrderId(storeOrder.Id).ToList(); var currentStores = Business.GetStoreSBusiness().GetByStoreOrderDetailIds(storeDetails.Select(r => r.Id).ToList()); var stores = new List <Data.Store>(); foreach (var item in storeDetails) { var currentStore = currentStores.Find(r => r.IdStoreOrderDetail == item.Id); var previousStore = Business.GetStoreSBusiness().GetLastForCommodity(item.IdCommodity); var remained = 0; if (previousStore != null) { remained = previousStore.SRemained.ToInt(); } var coef = Business.GetGoodyConvertCountingUnitBusiness().FindCoefficient(item.IdCommodity, goody.CBaseCountingUnit.ToGUID(), item.ODCountingUnit); var store = new Data.Store() { IdStoreOrderDetail = item.Id, RegDate = currentStore == null ? DateTime.Now : currentStore.RegDate, EditDate = DateTime.Now, SCount = item.ODCount, SRemained = remained + currentStore.SCount - (item.ODCount * coef).ToInt(), Sname = repository.Id, IdStoreOperation = Common.Constants.StoreOperation.PurchaseInvoice, IdCommodity = item.IdCommodity }; Business.GetStoreSBusiness().Insert(store); item.IdStoreS = store.Id; } Business.GetStoreOrderDetailBusiness().SubmitChanges(); Business.GetStoreSBusiness().Delete(currentStores); scope.Complete(); } } catch { throw; } }
/// <summary> /// returns store order detail by commodityid and unit count /// </summary> /// <param name="commodityId"></param> /// <param name="guid2"></param> /// <returns></returns> public StoreOrderDetail GetByCommodity(Data.StoreOrder storeOrder, Guid commodityId, Guid unitCountId) { try { return(this.GetAll().FirstOrDefault(r => r.IdCommodity == commodityId && r.ODCountingUnit == unitCountId && r.IdStoreOrder == storeOrder.Id)); } catch { throw; } }
/// <summary> /// ثبت سند خودکار برای فاکتور فروش /// </summary> /// <param name="storeOrder"></param> public void SaveAutomaticDocumentForSaleInvoice(Data.StoreOrder storeOrder) { try { var document = new Data.AccountingDocument() { ADCode = this.GetNextCode(), ADType = Common.Constants.DocumentType.SaleInvoice, ADDate = storeOrder.ODate, ADDescription = storeOrder.ODescription, AIdStatus = Common.Constants.DocumentStatus.TemporaryApproved, AISDeleted = false }; this.Save(document); Business.GetAccountingArticleBusiness().SaveAutomaticForSaleInvoice(storeOrder, document); } catch { throw; } }