internal async Task <DocSecondHandPurch2Tab> mPutPostDocSecondHandPurch2Tab( DbConnectionSklad db, //Models.Sklad.Doc.DocSecondHandPurch docSecondHandPurch, DocSecondHandPurch2Tab docSecondHandPurch2Tab, Classes.Account.Login.Field field //Дополнительные данные о сотруднике ) { #region Лог //Пишем в Лог о смене статуса и мастера, если такое было logSecondHand.DocSecondHandPurchID = docSecondHandPurch2Tab.DocSecondHandPurchID; logSecondHand.DirSecondHandLogTypeID = 6; logSecondHand.DirEmployeeID = field.DirEmployeeID; logSecondHand.DirSecondHandStatusID = null; if (docSecondHandPurch2Tab.DocSecondHandPurch2TabID == null) { logSecondHand.Msg = "Создание записи " + docSecondHandPurch2Tab.DirNomenName + " на сумму " + docSecondHandPurch2Tab.PriceCurrency; } else { logSecondHand.Msg = "Изменение записи " + docSecondHandPurch2Tab.DirNomenName + " на сумму " + docSecondHandPurch2Tab.PriceCurrency; } await logSecondHandsController.mPutPostLogSecondHands(db, logSecondHand, EntityState.Added); #endregion #region Save docSecondHandPurch2Tab.TabDate = DateTime.Now; if (docSecondHandPurch2Tab.DocSecondHandPurch2TabID > 0) { db.Entry(docSecondHandPurch2Tab).State = EntityState.Modified; } else { db.Entry(docSecondHandPurch2Tab).State = EntityState.Added; } await Task.Run(() => db.SaveChangesAsync()); #endregion #region Партии *** *** *** *** *** *** *** *** Controllers.Sklad.Rem.RemPartyMinusesController remPartyMinuses = new Rem.RemPartyMinusesController(); //Находим "DocSecondHandPurch" по "docSecondHandPurch2Tab.DocSecondHandPurchID" Models.Sklad.Doc.DocSecondHandPurch docSecondHandPurch = await db.DocSecondHandPurches.FindAsync(docSecondHandPurch2Tab.DocSecondHandPurchID); Models.Sklad.Doc.Doc doc = await db.Docs.FindAsync(docSecondHandPurch.DocID); #region Ищим в Возврате покупателя, если нет, то удаляем в RemPartyMinuses *** *** *** *** *** //Ищим в Возврате покупателя var queryRemPartyMinuses = await ( from x in db.RemPartyMinuses where x.DocID == docSecondHandPurch.DocID select x ).ToListAsync(); for (int i = 0; i < queryRemPartyMinuses.Count(); i++) { int iRemPartyMinusID = Convert.ToInt32(queryRemPartyMinuses[i].RemPartyMinusID); var queryDocReturnsCustomerTab = await ( from x in db.DocReturnsCustomerTabs where x.RemPartyMinusID == iRemPartyMinusID select x ).ToListAsync(); if (queryDocReturnsCustomerTab.Count() > 0) { throw new System.InvalidOperationException( Classes.Language.Sklad.Language.msg117 + "<tr>" + "<td>" + queryDocReturnsCustomerTab[0].RemPartyMinusID + "</td>" + //партия списания "<td>" + queryDocReturnsCustomerTab[0].DocReturnsCustomerID + "</td>" + //№ д-та "<td>" + queryDocReturnsCustomerTab[0].DirNomenID + "</td>" + //Код товара "<td>" + queryDocReturnsCustomerTab[0].Quantity + "</td>" + //списуемое к-во "</tr>" + "</table>" + Classes.Language.Sklad.Language.msg117_1 ); } //1.1. Удаляем "RemPartyMinuses" - не удаляем!!! //Models.Sklad.Rem.RemPartyMinus _remPartyMinus = await db.RemPartyMinuses.FindAsync(iRemPartyMinusID); //db.RemPartyMinuses.Remove(_remPartyMinus); //await db.SaveChangesAsync(); } #endregion #region Удаляем все записи из таблицы "RemPartyMinuses" - не удаляем!!! //Удаляем все записи из таблицы "RemPartyMinuses" //Что бы правильно Проверяло на Остаток. //А то, товар уже списан, а я проверяю на остаток! //await Task.Run(() => remPartyMinuses.Delete(db, Convert.ToInt32(docSecondHandPurch.DocID))); //remPartyMinuses.Delete(db, Convert.ToInt32(doc.DocID))); #endregion #region Проверки и Списание с партий (RemPartyMinuses) #region Проверка //Переменные int iRemPartyID = docSecondHandPurch2Tab.RemPartyID; double dQuantity = 1; // docSecondHandPurch2Tab.Quantity; //Находим партию Models.Sklad.Rem.RemParty remParty = await db.RemParties.FindAsync(iRemPartyID); db.Entry(remParty).Reload(); // - Это Важно! Триггер изменил значения, то они НЕ видны в проекте, надо обновить значения!!! #region 1. Есть ли остаток в партии с которой списываем! if (remParty.Remnant < dQuantity) { throw new System.InvalidOperationException( Classes.Language.Sklad.Language.msg104 + "<tr>" + "<td>" + docSecondHandPurch2Tab.RemPartyID + "</td>" + //партия "<td>" + docSecondHandPurch2Tab.DirNomenID + "</td>" + //Код товара "<td>1</td>" + //"<td>" + docSecondHandPurch2Tab.Quantity + "</td>" //списуемое к-во "<td>" + remParty.Remnant + "</td>" + //остаток партии "<td>" + (1 - remParty.Remnant).ToString() + "</td>" + //"<td>" + (docSecondHandPurch2Tab.Quantity - remParty.Remnant).ToString() + "</td>" //недостающее к-во "</tr>" + "</table>" + Classes.Language.Sklad.Language.msg104_1 ); } #endregion #region 2. Склад: склад документа должен соответствовать каждой списуемой партии! if (remParty.DirWarehouseID != docSecondHandPurch.DirWarehouseID) { //Это нужно, т.к. к нам от клиента не пришли все значения модели: "docSecondHandPurch.dirWarehouse.DirWarehouseName" Models.Sklad.Dir.DirWarehouse dirWarehouse = await db.DirWarehouses.FindAsync(docSecondHandPurch.DirWarehouseID); throw new System.InvalidOperationException( Classes.Language.Sklad.Language.msg105 + "<tr>" + "<td>" + docSecondHandPurch2Tab.RemPartyID + "</td>" + //партия "<td>" + docSecondHandPurch2Tab.DirNomenID + "</td>" + //Код товара "<td>" + dirWarehouse.DirWarehouseName + "</td>" + //склад документа "<td>" + remParty.dirWarehouse.DirWarehouseName + "</td>" + //склад партии "</tr>" + "</table>" + Classes.Language.Sklad.Language.msg105_1 ); } #endregion #region 3. Организация: организация документа должен соответствовать каждой списуемой партии! if (remParty.DirContractorIDOrg != doc.DirContractorIDOrg) { //Это нужно, т.к. к нам от клиента не пришли все значения модели: "docSecondHandPurch.dirWarehouse.DirWarehouseName" Models.Sklad.Dir.DirContractor dirContractor = await db.DirContractors.FindAsync(doc.DirContractorIDOrg); throw new System.InvalidOperationException( Classes.Language.Sklad.Language.msg106 + "<tr>" + "<td>" + docSecondHandPurch2Tab.RemPartyID + "</td>" + //партия "<td>" + docSecondHandPurch2Tab.DirNomenID + "</td>" + //Код товара "<td>" + dirContractor.DirContractorName + "</td>" + //организация спецификации "<td>" + remParty.dirContractorOrg.DirContractorName + "</td>" + //организация партии "</tr>" + "</table>" + Classes.Language.Sklad.Language.msg106_1 ); } #endregion #endregion #region Сохранение Models.Sklad.Rem.RemPartyMinus remPartyMinus = new Models.Sklad.Rem.RemPartyMinus(); remPartyMinus.RemPartyMinusID = null; remPartyMinus.RemPartyID = docSecondHandPurch2Tab.RemPartyID; remPartyMinus.DirNomenID = Convert.ToInt32(docSecondHandPurch2Tab.DirNomenID); remPartyMinus.Quantity = 1; // docSecondHandPurch2Tab.Quantity; remPartyMinus.DirCurrencyID = docSecondHandPurch2Tab.DirCurrencyID; remPartyMinus.DirCurrencyMultiplicity = docSecondHandPurch2Tab.DirCurrencyMultiplicity; remPartyMinus.DirCurrencyRate = docSecondHandPurch2Tab.DirCurrencyRate; remPartyMinus.DirVatValue = docSecondHandPurch.DirVatValue; remPartyMinus.DirWarehouseID = docSecondHandPurch.DirWarehouseID; remPartyMinus.DirContractorIDOrg = doc.DirContractorIDOrg; remPartyMinus.DirContractorID = doc.DirContractorIDOrg; remPartyMinus.DocID = Convert.ToInt32(docSecondHandPurch.DocID); remPartyMinus.PriceCurrency = docSecondHandPurch2Tab.PriceCurrency; remPartyMinus.PriceVAT = docSecondHandPurch2Tab.PriceVAT; remPartyMinus.FieldID = Convert.ToInt32(docSecondHandPurch2Tab.DocSecondHandPurch2TabID); remPartyMinus.Reserve = false; //docSecondHandPurch.Reserve; remPartyMinus.DirEmployeeID = doc.DirEmployeeID; remPartyMinus.DocDate = doc.DocDate; db.Entry(remPartyMinus).State = EntityState.Added; await db.SaveChangesAsync(); #endregion #endregion #endregion return(docSecondHandPurch2Tab); }
public async Task <IHttpActionResult> PostDocSecondHandPurch2Tab(DocSecondHandPurch2Tab docSecondHandPurch2Tab) { try { #region Проверяем Логин и Пароль + Изменяем строку соединения + Права + Разные Функции //Получаем Куку System.Web.HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies["CookieIPOL"]; // Проверяем Логин и Пароль Classes.Account.Login.Field field = await Task.Run(() => login.Return(authCookie, true)); if (!field.Access) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg10))); } //Изменяем строку соединения db = new DbConnectionSklad(connectionString.Return(field.DirCustomersID, null, true)); //Права (1 - Write, 2 - Read, 3 - No Access) int iRight = await Task.Run(() => accessRight.Access(connectionString.Return(field.DirCustomersID, null, true), field.DirEmployeeID, "RightDocSecondHandPurch2Tabs")); if (iRight != 1) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0)))); } //Разные Функции function.NumberDecimalSeparator(); //Получам настройки Models.Sklad.Sys.SysSetting sysSetting = await db.SysSettings.FindAsync(1); #endregion #region Параметры //Получаем колекцию "Спецификации" Models.Sklad.Doc.DocSecondHandPurch2Tab[] DocSecondHandPurch2TabCollection = null; if (!String.IsNullOrEmpty(docSecondHandPurch2Tab.recordsDataX)) { JavaScriptSerializer serializer = new JavaScriptSerializer(); DocSecondHandPurch2TabCollection = serializer.Deserialize <Models.Sklad.Doc.DocSecondHandPurch2Tab[]>("[" + docSecondHandPurch2Tab.recordsDataX + "]"); } if (DocSecondHandPurch2TabCollection.Length > 0) { docSecondHandPurch2Tab = DocSecondHandPurch2TabCollection[0]; docSecondHandPurch2Tab.PriceVAT = docSecondHandPurch2Tab.PriceCurrency; //if (docSecondHandPurch2Tab.DirSecondHandJobNomenID == 0) docSecondHandPurch2Tab.DirSecondHandJobNomenID = null; if (docSecondHandPurch2Tab.DocSecondHandPurch2TabID == null || docSecondHandPurch2Tab.DocSecondHandPurch2TabID < 1) { docSecondHandPurch2Tab.DocSecondHandPurch2TabID = null; docSecondHandPurch2Tab.DirEmployeeID = field.DirEmployeeID; docSecondHandPurch2Tab.DirCurrencyID = sysSetting.DirCurrencyID; docSecondHandPurch2Tab.DirCurrencyRate = 1; docSecondHandPurch2Tab.DirCurrencyMultiplicity = 1; } } #endregion #region Сохранение using (System.Data.Entity.DbContextTransaction ts = db.Database.BeginTransaction()) { db.Configuration.AutoDetectChangesEnabled = false; try { docSecondHandPurch2Tab = await Task.Run(() => mPutPostDocSecondHandPurch2Tab(db, docSecondHandPurch2Tab, field)); ts.Commit(); } catch (Exception ex) { try { ts.Rollback(); ts.Dispose(); } catch { } try { db.Database.Connection.Close(); db.Database.Connection.Dispose(); } catch { } return(Ok(returnServer.Return(false, exceptionEntry.Return(ex)))); } } dynamic collectionWrapper = new { DocSecondHandPurch2TabID = docSecondHandPurch2Tab.DocSecondHandPurch2TabID, DirEmployeeID = docSecondHandPurch2Tab.DirEmployeeID, DirCurrencyID = docSecondHandPurch2Tab.DirCurrencyID, DirCurrencyRate = docSecondHandPurch2Tab.DirCurrencyRate, DirCurrencyMultiplicity = docSecondHandPurch2Tab.DirCurrencyMultiplicity }; return(Ok(returnServer.Return(true, collectionWrapper))); //return Ok(returnServer.Return(true, "")); #endregion } catch (Exception ex) { return(Ok(returnServer.Return(false, exceptionEntry.Return(ex)))); } }
public async Task <IHttpActionResult> DeleteDocSecondHandPurch2Tab(int id) { #region Проверяем Логин и Пароль + Изменяем строку соединения + Права + Разные Функции //Получаем Куку System.Web.HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies["CookieIPOL"]; // Проверяем Логин и Пароль Classes.Account.Login.Field field = await Task.Run(() => login.Return(authCookie, true)); if (!field.Access) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg10))); } //Изменяем строку соединения db = new DbConnectionSklad(connectionString.Return(field.DirCustomersID, null, true)); //Права (1 - Write, 2 - Read, 3 - No Access) int iRight = await Task.Run(() => accessRight.Access(connectionString.Return(field.DirCustomersID, null, true), field.DirEmployeeID, "RightDocSecondHandPurch2Tabs")); if (iRight != 1) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0)))); } //Разные Функции function.NumberDecimalSeparator(); //Получам настройки Models.Sklad.Sys.SysSetting sysSetting = await db.SysSettings.FindAsync(1); #endregion #region Удаление try { DocSecondHandPurch2Tab docSecondHandPurch2Tab = await db.DocSecondHandPurch2Tabs.FindAsync(id); if (docSecondHandPurch2Tab == null) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg99))); } using (System.Data.Entity.DbContextTransaction ts = db.Database.BeginTransaction()) { db.Configuration.AutoDetectChangesEnabled = false; try { #region Лог //Пишем в Лог о смене статуса и мастера, если такое было logSecondHand.DocSecondHandPurchID = docSecondHandPurch2Tab.DocSecondHandPurchID; logSecondHand.DirSecondHandLogTypeID = 6; logSecondHand.DirEmployeeID = field.DirEmployeeID; logSecondHand.DirSecondHandStatusID = null; logSecondHand.Msg = "Удаление записи " + docSecondHandPurch2Tab.DirNomenName + " на сумму " + docSecondHandPurch2Tab.PriceCurrency; await logSecondHandsController.mPutPostLogSecondHands(db, logSecondHand, EntityState.Added); #endregion #region Save db.DocSecondHandPurch2Tabs.Remove(docSecondHandPurch2Tab); await db.SaveChangesAsync(); #endregion #region Партии Models.Sklad.Doc.DocSecondHandPurch docSecondHandPurch = await db.DocSecondHandPurches.FindAsync(docSecondHandPurch2Tab.DocSecondHandPurchID); //Models.Sklad.Rem.RemPartyMinus remPartyMinus = db.RemPartyMinuses.Where(x => x.DocID == docSecondHandPurch.DocID && x.FieldID == id).ToList().First(); var query = await db.RemPartyMinuses.Where(x => x.DocID == docSecondHandPurch.DocID && x.FieldID == id).ToListAsync(); if (query.Count() > 0) { Models.Sklad.Rem.RemPartyMinus remPartyMinus = query[0]; db.RemPartyMinuses.Remove(remPartyMinus); await db.SaveChangesAsync(); } #endregion ts.Commit(); } catch (Exception ex) { try { ts.Rollback(); ts.Dispose(); } catch { } try { db.Database.Connection.Close(); db.Database.Connection.Dispose(); } catch { } return(Ok(returnServer.Return(false, exceptionEntry.Return(ex)))); } } dynamic collectionWrapper = new { ID = docSecondHandPurch2Tab.DocSecondHandPurch2TabID, Msg = Classes.Language.Sklad.Language.msg19 }; return(Ok(returnServer.Return(true, collectionWrapper))); //return Ok(returnServer.Return(true, "") } catch (Exception ex) { return(Ok(returnServer.Return(false, exceptionEntry.Return(ex)))); } #endregion }
public async Task <IHttpActionResult> PutDocSecondHandPurch2Tab(int id, DocSecondHandPurch2Tab docSecondHandPurch2Tab) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0)))); }