コード例 #1
0
        internal async Task <string> mSms_DocServicePurches(
            DbConnectionSklad db,
            DirSmsTemplate dirSmsTemplate,
            DocServicePurch docServicePurch,
            Models.Sklad.Sys.SysSetting sysSetting
            )
        {
            string ret = dirSmsTemplate.DirSmsTemplateMsg;

            //Парсим текст

            //Ваш (тип устройства/марка/модель) Mob.tel/Nokia/535 принят в ремонт, номер ремонта 2005
            //Мастерская Сити-Мастер
            //тел (тут вставляем номер тел точки чтоб чел мог набрать)


            //1. DirServiceNomenName: надо получить полное наименование
            Controllers.Sklad.Doc.DocServicePurches.DocServicePurchesController docServicePurchesController = new Controllers.Sklad.Doc.DocServicePurches.DocServicePurchesController();
            string[] DirServiceNomenPatchFullarr = await Task.Run(() => docServicePurchesController.mPatchFull(db, docServicePurch.DirServiceNomenID));

            string DirServiceNomenPatchFull = DirServiceNomenPatchFullarr[0];

            ret = ret.Replace("[[[ТоварНаименование]]]", DirServiceNomenPatchFull);


            //2. DocServicePurchID
            ret = ret.Replace("[[[ДокументНомер]]]", docServicePurch.DocServicePurchID.ToString());


            //3. Организация: получаем из настроек
            Models.Sklad.Dir.DirContractor dirContractor = await db.DirContractors.FindAsync(sysSetting.DirContractorIDOrg);

            ret = ret.Replace("[[[Организация]]]", dirContractor.DirContractorName);


            //4. Телефон: получаем из "docServicePurch.DirWarehouseID"
            Models.Sklad.Dir.DirWarehouse dirWarehouse = await db.DirWarehouses.FindAsync(docServicePurch.DirWarehouseID);

            ret = ret.Replace("[[[ТочкаНаименование]]]", dirWarehouse.DirWarehouseName);
            ret = ret.Replace("[[[ТочкаАдрес]]]", dirWarehouse.DirWarehouseAddress);
            ret = ret.Replace("[[[ТочкаТелефон]]]", dirWarehouse.Phone);


            //5. [[[Сумма]]]
            ret = ret.Replace("[[[Сумма]]]", docServicePurch.Sums.ToString()); //SumsTotal



            return(ret);
        }
コード例 #2
0
        internal async Task <DocServicePurch2Tab> mPutPostDocServicePurch2Tab(
            DbConnectionSklad db,
            Models.Sklad.Doc.DocServicePurch docServicePurch,
            DocServicePurch2Tab docServicePurch2Tab,

            Classes.Account.Login.Field field //Дополнительные данные о сотруднике
            )
        {
            #region Лог

            //Пишем в Лог о смене статуса и мастера, если такое было
            logService.DocServicePurchID   = docServicePurch2Tab.DocServicePurchID;
            logService.DirServiceLogTypeID = 6;
            logService.DirEmployeeID       = field.DirEmployeeID;
            logService.DirServiceStatusID  = null;
            if (docServicePurch2Tab.DocServicePurch2TabID == null)
            {
                logService.Msg = "Создание записи " + docServicePurch2Tab.DirNomenName + " на сумму " + docServicePurch2Tab.PriceCurrency;
            }
            else
            {
                logService.Msg = "Изменение записи " + docServicePurch2Tab.DirNomenName + " на сумму " + docServicePurch2Tab.PriceCurrency;
            }

            await logServicesController.mPutPostLogServices(db, logService, EntityState.Added);

            #endregion


            #region Save

            docServicePurch2Tab.TabDate = DateTime.Now;

            if (docServicePurch2Tab.DocServicePurch2TabID > 0)
            {
                db.Entry(docServicePurch2Tab).State = EntityState.Modified;
            }
            else
            {
                db.Entry(docServicePurch2Tab).State = EntityState.Added;
            }
            await Task.Run(() => db.SaveChangesAsync());

            #endregion

            #region Партии *** *** *** *** *** *** *** ***


            Controllers.Sklad.Rem.RemPartyMinusesController remPartyMinuses = new Rem.RemPartyMinusesController();

            //Находим "DocServicePurch" по "docServicePurch2Tab.DocServicePurchID"
            //Models.Sklad.Doc.DocServicePurch docServicePurch = await db.DocServicePurches.FindAsync(docServicePurch2Tab.DocServicePurchID);
            Models.Sklad.Doc.Doc doc = await db.Docs.FindAsync(docServicePurch.DocID);


            #region Ищим в Возврате покупателя, если нет, то удаляем в RemPartyMinuses *** *** *** *** ***

            //Ищим в Возврате покупателя
            var queryRemPartyMinuses = await
                                       (
                from x in db.RemPartyMinuses
                where x.DocID == docServicePurch.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(docServicePurch.DocID)));  //remPartyMinuses.Delete(db, Convert.ToInt32(doc.DocID)));

            #endregion


            #region Проверки и Списание с партий (RemPartyMinuses)


            #region Проверка

            //Переменные
            int    iRemPartyID = docServicePurch2Tab.RemPartyID;
            double dQuantity   = 1; // docServicePurch2Tab.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>" + docServicePurch2Tab.RemPartyID + "</td>" +    //партия
                          "<td>" + docServicePurch2Tab.DirNomenID + "</td>" +    //Код товара
                          "<td>1</td>" +                                         //"<td>" + docServicePurch2Tab.Quantity + "</td>"                                 //списуемое к-во
                          "<td>" + remParty.Remnant + "</td>" +                  //остаток партии
                          "<td>" + (1 - remParty.Remnant).ToString() + "</td>" + //"<td>" + (docServicePurch2Tab.Quantity - remParty.Remnant).ToString() + "</td>" //недостающее к-во
                          "</tr>" +
                          "</table>" +

                          Classes.Language.Sklad.Language.msg104_1
                          );
            }
            #endregion

            #region 2. Склад: склад документа должен соответствовать каждой списуемой партии!
            if (remParty.DirWarehouseID != docServicePurch.DirWarehouseID)
            {
                //Это нужно, т.к. к нам от клиента не пришли все значения модели: "docServicePurch.dirWarehouse.DirWarehouseName"
                Models.Sklad.Dir.DirWarehouse dirWarehouse = await db.DirWarehouses.FindAsync(docServicePurch.DirWarehouseID);

                throw new System.InvalidOperationException(
                          Classes.Language.Sklad.Language.msg105 +

                          "<tr>" +
                          "<td>" + docServicePurch2Tab.RemPartyID + "</td>" +         //партия
                          "<td>" + docServicePurch2Tab.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)
            {
                //Это нужно, т.к. к нам от клиента не пришли все значения модели: "docServicePurch.dirWarehouse.DirWarehouseName"
                Models.Sklad.Dir.DirContractor dirContractor = await db.DirContractors.FindAsync(doc.DirContractorIDOrg);

                throw new System.InvalidOperationException(
                          Classes.Language.Sklad.Language.msg106 +

                          "<tr>" +
                          "<td>" + docServicePurch2Tab.RemPartyID + "</td>" +              //партия
                          "<td>" + docServicePurch2Tab.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              = docServicePurch2Tab.RemPartyID;
            remPartyMinus.DirNomenID              = Convert.ToInt32(docServicePurch2Tab.DirNomenID);
            remPartyMinus.Quantity                = 1; // docServicePurch2Tab.Quantity;
            remPartyMinus.DirCurrencyID           = docServicePurch2Tab.DirCurrencyID;
            remPartyMinus.DirCurrencyMultiplicity = docServicePurch2Tab.DirCurrencyMultiplicity;
            remPartyMinus.DirCurrencyRate         = docServicePurch2Tab.DirCurrencyRate;
            remPartyMinus.DirVatValue             = docServicePurch.DirVatValue;
            remPartyMinus.DirWarehouseID          = docServicePurch.DirWarehouseID;
            remPartyMinus.DirContractorIDOrg      = doc.DirContractorIDOrg;
            remPartyMinus.DirContractorID         = doc.DirContractorIDOrg;
            remPartyMinus.DocID         = Convert.ToInt32(docServicePurch.DocID);
            remPartyMinus.PriceCurrency = docServicePurch2Tab.PriceCurrency;
            remPartyMinus.PriceVAT      = docServicePurch2Tab.PriceVAT;
            remPartyMinus.FieldID       = Convert.ToInt32(docServicePurch2Tab.DocServicePurch2TabID);
            remPartyMinus.Reserve       = false; //docServicePurch.Reserve;

            remPartyMinus.DirEmployeeID = doc.DirEmployeeID;
            remPartyMinus.DocDate       = doc.DocDate;

            db.Entry(remPartyMinus).State = EntityState.Added;
            await db.SaveChangesAsync();

            #endregion


            #endregion


            #endregion


            return(docServicePurch2Tab);
        }
コード例 #3
0
        public async Task <IHttpActionResult> GetDirContractor(int id, HttpRequestMessage request)
        {
            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, "RightDirContractors"));

                if (iRight == 3)
                {
                    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 Параметры

                Params _params = new Params();

                //paramList -список параметров
                var paramList = request.GetQueryNameValuePairs();
                //Параметры
                _params.parSearch = paramList.FirstOrDefault(kv => string.Compare(kv.Key, "parSearch", true) == 0).Value; if (_params.parSearch != null)
                {
                    _params.parSearch = _params.parSearch.ToLower();                                                                                                                                      //Поиск
                }
                //Пришли за "Градационной Скидкой"
                _params.Discount = Convert.ToInt32(paramList.FirstOrDefault(kv => string.Compare(kv.Key, "Discount", true) == 0).Value);   //Номер страницы

                #endregion

                if (_params.Discount == 0)
                {
                    #region Отправка JSON

                    var query = await Task.Run(() =>
                                               (

                                                   from x in db.DirContractors

                                                   join dirDiscounts1 in db.DirDiscounts on x.DirDiscountID equals dirDiscounts1.DirDiscountID into dirDiscounts2
                                                   from dirDiscounts in dirDiscounts2.DefaultIfEmpty()

                                                   join dirBanks1 in db.DirBanks on x.DirBankID equals dirBanks1.DirBankID into dirBanks2
                                                   from dirBanks in dirBanks2.DefaultIfEmpty()

                                                   where x.DirContractorID == id
                                                   select new
                    {
                        DirContractorID = x.DirContractorID,
                        Del = x.Del,
                        DirContractorName = x.DirContractorName,
                        NameLower = x.NameLower,
                        DirContractorAddress = x.DirContractorAddress,

                        DirContractor1TypeID = x.DirContractor1TypeID,
                        DirContractor1TypeName = x.dirContractor1Type.DirContractor1TypeName,

                        DirContractor2TypeID = x.DirContractor2TypeID,
                        DirContractor2TypeName = x.dirContractor2Type.DirContractor2TypeName,

                        DirContractorPhone = x.DirContractorPhone,
                        DirContractorFax = x.DirContractorFax,
                        DirContractorEmail = x.DirContractorEmail,
                        DirContractorWWW = x.DirContractorWWW,

                        DirContractorDiscount = x.DirContractorDiscount,

                        DirDiscountID = x.DirDiscountID,
                        DirDiscountName = dirDiscounts.DirDiscountName,

                        DirBankID = x.DirBankID,
                        DirBankName = dirBanks.DirBankName,

                        DirContractorDesc = x.DirContractorDesc,
                        ImageLink = x.ImageLink,
                        DirBankAccountName = x.DirBankAccountName
                    }

                                               ).ToListAsync());


                    if (query.Count() > 0)
                    {
                        return(Ok(returnServer.Return(true, query[0])));
                    }
                    else
                    {
                        return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg89)));
                    }

                    //return Ok(returnServer.Return(false, Classes.Language.Language.msg89));

                    #endregion
                }
                else
                {
                    #region Отправка JSON

                    Models.Sklad.Dir.DirContractor dirContractor = await db.DirContractors.FindAsync(id);

                    int    iDirDiscountID = Convert.ToInt32(dirContractor.DirDiscountID);
                    double dSalesSum      = dirContractor.SalesSum;

                    var query = await Task.Run(() =>
                                               (
                                                   from x in db.DirDiscountTabs
                                                   where x.DirDiscountID == iDirDiscountID && dSalesSum < x.SumBegin
                                                   select new
                    {
                        Discount = x.Discount == null ? 0 : x.Discount
                    }
                                               ).MaxAsync(x => x.Discount));


                    dynamic collectionWrapper = new
                    {
                        sucess = true,
                        DirContractorDiscount = query
                    };
                    return(await Task.Run(() => Ok(collectionWrapper)));

                    #endregion
                }
            }
            catch (Exception ex)
            {
                return(Ok(returnServer.Return(false, exceptionEntry.Return(ex))));
            }
        }