Пример #1
0
        /// <summary>
        /// Додавання позицій в документ по коду одиниці
        /// </summary>
        /// <param name="WareCode"></param>
        /// <returns></returns>
        private WareDocumentDetail AddDocumenDetailByWareCode(string WareCode)
        {
            DocumentDetailsLogic details        = new DocumentDetailsLogic(manager);
            WareCodesLogic       wareCodesLogic = new WareCodesLogic(manager);
            WareDocumentDetail   result         = null;
            Ware ware = wareCodesLogic.GetWareByCode(WareCode);

            if (ware != null)
            {
                int     wareId                = ware.ID;
                decimal unitQuantity          = 1;
                decimal secondaryUnitQuantity = 0;
                decimal priceForUnit          = 0;
                decimal discountForUnit       = 0;
                decimal endSalePriceForUnit   = 0;
                decimal endPrice              = 0;

                int currencyId   = Convert.ToInt32(CurrencyLUE.EditValue);
                int priceGroupID = 1;

                WareDocumentDetail DocumentDetail = new WareDocumentDetail();
                //створюємо новий запис в деталізації документа і повертаємо його
                DocumentDetail = details.CreateWithNoSave(wareId, unitQuantity, secondaryUnitQuantity,
                                                          priceForUnit, discountForUnit, endSalePriceForUnit, endPrice, currencyId, priceGroupID);
                documentDetailsView.Add(DocumentDetail);
                result = DocumentDetail;
                FillDetails();
            }
            else
            {
                MessageBox.Show("Товар з даним кодом не знайдено");
            }
            return(result);
        }
Пример #2
0
        public void Recalculate(DateTime StartDate)
        {
            DocumentsLogic            documents    = new DocumentsLogic(manager);
            DocumentDetailsLogic      detailsLogic = new DocumentDetailsLogic(manager);
            List <WareDocumentDetail> details      = detailsLogic.GetAll(StartDate);

            foreach (WareDocumentDetail detail in details)
            {
                if (detail.WareDocument.FromStructureObjectID != null)
                {
                    this.UpdateCurrentRemainByDocumentDetail(StartDate, detail.WareID, detail.WareDocument.FromStructureObjectID, null);
                }
                if (detail.WareDocument.ToStructureObjectD != null)
                {
                    this.UpdateCurrentRemainByDocumentDetail(StartDate, detail.WareID, detail.WareDocument.ToStructureObjectD, null);
                }
            }
        }
Пример #3
0
        private void SaveBt_Click(object sender, EventArgs e)
        {
            DocumentDetailsLogic details = new DocumentDetailsLogic(manager);

            if (wareSelectorUC1.WareID != null)
            {
                int     wareId                = (int)(wareSelectorUC1.WareID);
                decimal unitQuantity          = Convert.ToDecimal(UnitQuantityNUD.Value);
                decimal secondaryUnitQuantity = Convert.ToDecimal(SecondaryUnitQuantityNUD.Value);
                decimal priceForUnit          = Convert.ToDecimal(UnitPriceNUD.Value);
                decimal discountForUnit       = Convert.ToDecimal(DiscountForUnitNUD.Value);
                decimal endSalePriceForUnit   = Convert.ToDecimal(priceForUnit - discountForUnit);
                decimal endPrice              = Convert.ToDecimal(endSalePriceForUnit * unitQuantity);
                int     currencyId            = Convert.ToInt32(Document.CurrencyID);



                //MessageBox.Show(wareId.ToString());
                if (mode == "new")
                {
                    //створюємо новий запис в деталізації документа і повертаємо його
                    DocumentDetail = details.CreateWithNoSave(wareId, unitQuantity, secondaryUnitQuantity,
                                                              priceForUnit, discountForUnit, endSalePriceForUnit, endPrice, currencyId, -1);
                    DocumentDetails.Add(DocumentDetail);
                }
                if (mode == "edit")
                {
                    //DocumentDetails.Remove(DocumentDetail);
                    DocumentDetail.UnitQuantity          = unitQuantity;
                    DocumentDetail.SecondaryUnitQuantity = secondaryUnitQuantity;
                    DocumentDetail.PriceForUnit          = priceForUnit;
                    DocumentDetail.DiscountForUnit       = discountForUnit;
                    DocumentDetail.EndPriceForUnit       = endSalePriceForUnit;
                    DocumentDetail.EndPrice   = endPrice;
                    DocumentDetail.CurrencyID = currencyId;

                    //DocumentDetails.Add(DocumentDetail);
                }
                //manager.Save();
                MessageL.Text = "Додано";
            }
        }
Пример #4
0
        private void SaveBt_Click(object sender, EventArgs e)
        {
            if (dxValidationProvider1.Validate() == true)
            {
                DocumentDetailsLogic details = new DocumentDetailsLogic(manager);
                int     wareId                = (int)(WareLUE.EditValue);
                decimal unitQuantity          = Convert.ToDecimal(UnitQuantityTB.Text);
                decimal secondaryUnitQuantity = Convert.ToDecimal(SecondaryUnitQuantityTB.Text);
                decimal priceForUnit          = Convert.ToDecimal(SalePriceForUnitTB.Text);
                decimal discountForUnit       = Convert.ToDecimal(DiscountForUnitTB.Text);
                decimal endSalePriceForUnit   = Convert.ToDecimal(EndSalePriceForUnitTB.Text);
                decimal endPrice              = Convert.ToDecimal(SalePriceTB.Text);
                int     currencyId            = Convert.ToInt32(CurrencyLUE.EditValue);
                int     priceGroupID          = Convert.ToInt32(PriceGroupsCBE.EditValue);

                //MessageBox.Show(wareId.ToString());
                if (mode == "new")
                {
                    //створюємо новий запис в деталізації документа і повертаємо його
                    DocumentDetail = details.CreateWithNoSave(wareId, unitQuantity, secondaryUnitQuantity,
                                                              priceForUnit, discountForUnit, endSalePriceForUnit, endPrice, currencyId, priceGroupID);
                    DocumentDetails.Add(DocumentDetail);
                }
                if (mode == "edit")
                {
                    //DocumentDetails.Remove(DocumentDetail);
                    DocumentDetail.UnitQuantity          = unitQuantity;
                    DocumentDetail.SecondaryUnitQuantity = secondaryUnitQuantity;
                    DocumentDetail.PriceForUnit          = priceForUnit;
                    DocumentDetail.DiscountForUnit       = discountForUnit;
                    DocumentDetail.EndPriceForUnit       = endSalePriceForUnit;
                    DocumentDetail.EndPrice   = endPrice;
                    DocumentDetail.CurrencyID = currencyId;

                    //DocumentDetails.Add(DocumentDetail);
                }
                //manager.Save();

                this.Close();
            }
        }
Пример #5
0
        /// <summary>
        /// Конструктор форми створення і редагування документу
        /// </summary>
        /// <param name="_mode">режим - new або edit</param>
        /// <param name="_id">ыдентифыкатор документу для режиму редагування</param>
        /// <param name="_CashRegister">підключений принтер чеків(якщо немає то null)</param>
        public DocumentData(string _mode, int? _id, CashRegister _CashRegister)
        {
            InitializeComponent();
            cashRegister = _CashRegister;
            CompasLogger.Add(String.Format("Start opening doc form"), CompasLogger.Level.Info);
            manager = new ContextManager();
            mode = _mode;

            id = _id;
            DetailsGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            FillPayments();
            documentDetailsNew = new List<WareDocumentDetail>();
            documentDetailsOld = new List<WareDocumentDetail>();
            documentDetailsDeleted = new List<WareDocumentDetail>();
            employeesDetailsView = new List<StaffEmployeeView>();
            documentsLogic = new DocumentsLogic(manager);
            documentDetailsLogic = new DocumentDetailsLogic(manager);
            if (mode == "new")
            {
                //створюємо документ в памяті
                document = documentsLogic.CreateEmpty();
            }

            if (mode == "edit")
            {
                //витягуємо документ в память
                document = documentsLogic.Get(Convert.ToInt32(id));
                //витягуємо детальну інформацію по документу
                documentDetailsOld = documentDetailsLogic.GetAll(id);
                documentDetailsView = documentDetailsOld;
                FillEmployeeDetails();

            }
            CompasLogger.Add(String.Format("p1"), CompasLogger.Level.Info);
            Fill();

            CompasLogger.Add(String.Format("End opening doc form"), CompasLogger.Level.Info);
        }
Пример #6
0
        /// <summary>
        /// Конструктор форми створення і редагування документу
        /// </summary>
        /// <param name="_mode">режим - new або edit</param>
        /// <param name="_id">ыдентифыкатор документу для режиму редагування</param>
        /// <param name="_CashRegister">підключений принтер чеків(якщо немає то null)</param>
        public DocumentData(string _mode, int?_id, CashRegister _CashRegister)
        {
            InitializeComponent();
            cashRegister = _CashRegister;
            CompasLogger.Add(String.Format("Start opening doc form"), CompasLogger.Level.Info);
            manager = new ContextManager();
            mode    = _mode;

            id = _id;
            DetailsGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            FillPayments();
            documentDetailsNew     = new List <WareDocumentDetail>();
            documentDetailsOld     = new List <WareDocumentDetail>();
            documentDetailsDeleted = new List <WareDocumentDetail>();
            employeesDetailsView   = new List <StaffEmployeeView>();
            documentsLogic         = new DocumentsLogic(manager);
            documentDetailsLogic   = new DocumentDetailsLogic(manager);
            if (mode == "new")
            {
                //створюємо документ в памяті
                document = documentsLogic.CreateEmpty();
            }

            if (mode == "edit")
            {
                //витягуємо документ в память
                document = documentsLogic.Get(Convert.ToInt32(id));
                //витягуємо детальну інформацію по документу
                documentDetailsOld  = documentDetailsLogic.GetAll(id);
                documentDetailsView = documentDetailsOld;
                FillEmployeeDetails();
            }
            CompasLogger.Add(String.Format("p1"), CompasLogger.Level.Info);
            Fill();

            CompasLogger.Add(String.Format("End opening doc form"), CompasLogger.Level.Info);
        }
Пример #7
0
        private void Fill()
        {
            int? selectedIndex = null;
            if (DataGV.SelectedRows.Count > 0)
            {
                selectedIndex = DataGV.SelectedRows[0].Index;
            }

            int? documentTypeId = null;
            string documentNumber = "";
            DateTime startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            DateTime? endDate = null;
            decimal? documentSum = null;

            if(documentFilterUC1.DocumentTypeID >= 0)
                documentTypeId = documentFilterUC1.DocumentTypeID;
            documentNumber = documentFilterUC1.DocumentNumber;
            startDate = universalFilter1.StartDate == null ? startDate : Convert.ToDateTime(universalFilter1.StartDate);
            endDate = universalFilter1.EndDate;
            documentSum = documentFilterUC1.DocumentSum;

            SortableBindingList<DocumentView> view =
                    new SortableBindingList<DocumentView>(documentsLogic.GetAllView(documentTypeId, documentNumber,
                        startDate, endDate, documentSum));

            //if (selectedIndex != null)
            //    if(DataGV.RowCount > selectedIndex)
            //     DataGV.Rows[Convert.ToInt32(selectedIndex)].Selected = true;

            DataTable table = new DataTable();

            table.Columns.Add("Дата", typeof(DateTime));
            table.Columns.Add("Адреса", typeof(string));

            WareCategoriesLogic categoriesLogic = new WareCategoriesLogic(manager);
            Compas.Logic.Documents.DocumentDetailsLogic detailsLogic = new DocumentDetailsLogic(manager);
            DocumentStaffDetailsLogic staffLogic = new DocumentStaffDetailsLogic(manager);
            WaresLogic waresLogic = new WaresLogic(manager);

            //Спочатку визначаємо яку категорію номенклатури нам необхідно проаналізувати
            int viewCategoryId = Convert.ToInt32(ViewCategoriesLUE.EditValue);

            List<WareCategory> categories = categoriesLogic.GetAllRoot().Where(a => a.ID != viewCategoryId).ToList();
            foreach (WareCategory category in categories)
            {
                table.Columns.Add(category.Name, typeof(string));

            }

            table.Columns.Add("Акт №", typeof(string));
            table.Columns.Add("Сума", typeof(decimal));
            table.Columns.Add("К-ть робіт", typeof(decimal));
            table.Columns.Add("К-ть виконавців", typeof(int));
            table.Columns.Add("К-ть на вик.", typeof(int));

            table.Columns.Add("Виконавець1", typeof(string));
            table.Columns.Add("Виконавець2", typeof(string));
            table.Columns.Add("Виконавець3", typeof(string));
            table.Columns.Add("Виконавець4", typeof(string));

            //Основні матеріали(номенклатура, включена в документ)

            List<WareCategory> viewCategories = categoriesLogic.GetAllChilds(viewCategoryId);
            //спочатку вкладені підкатегорії
            foreach (WareCategory category in viewCategories)
            {
                table.Columns.Add(category.Name, typeof(string));
            }
            //тоді номенклатурні одиниці даної категорії(без підкатегорій)
            List<Ware> wares = waresLogic.GetAll(viewCategoryId);
            //кожна номенклатурна одиниця - окрема колонка
            foreach (Ware ware in wares)
            {
                table.Columns.Add(ware.Name, typeof(decimal));
            }

            table.Columns.Add("Коментарі", typeof(string));

            categories = categoriesLogic.GetAllRoot().Where(a => a.ID != viewCategoryId).ToList();
            foreach (DocumentView document in view)
            {

                DataRow row = table.NewRow();
                row["Дата"] = document.Date;
                row["Адреса"] = "Адреса надання послуги";
                row["Акт №"] = document.Number;
                row["Сума"] = document.DocumentSum;

                row["К-ть виконавців"] = 0;
                row["К-ть на вик."] = 0;

                int counter = 0;
                //виводимо категорії по колонкам
                foreach (WareCategory category in categories)
                {
                    string detailsList = "";
                    List<WareDocumentDetail> details = detailsLogic.GetAllByWareCategory(startDate, endDate, category.ID, document.ID).Where(a => a.Ware.CategoryID != viewCategoryId).ToList();

                    foreach (WareDocumentDetail detail in details)
                    {
                        if (detailsList.Length > 0)
                            detailsList = detailsList + ";\n";
                        //стрічка містить перелік номенклатурних одиниць в межах категорії
                        detailsList = detailsList + detail.Ware.Name;
                        counter++;
                    }

                    if (row[category.Name] != null)
                    {
                        row[category.Name] = detailsList;
                    }
                }
                row["К-ть робіт"] = counter;

                //Працівники повязані з даним документом

                List<StaffEmployee> staffEmployees = staffLogic.GetStaffEmployeesByDocumentID(document.ID);

                counter = 1;

                string fullName = "";

                foreach (StaffEmployee employee in staffEmployees)
                {

                    fullName = employee.LastName + " " + employee.FirstName + " " + employee.MiddleName;

                    if (counter < 4)
                        row["Виконавець" + counter.ToString()] = fullName;
                    else
                        row["Виконавець" + counter.ToString()] = row["Виконавець" + counter.ToString()] + "; " + fullName;

                    counter = counter + 1;
                }

                //номенклатурні одиниці, пов'язані з документом

                string viewCategoryDetailsList = "";
                decimal startViewCounter = 0;
                List<WareDocumentDetail> viewCategoryDetailsAll = detailsLogic.GetAllByWareCategory(startDate, endDate, viewCategoryId, document.ID);
                List<WareDocumentDetail> viewCategoryDetails = viewCategoryDetailsAll.Where(a => a.Ware.CategoryID == viewCategoryId).ToList();

                foreach (WareDocumentDetail detail in viewCategoryDetails)
                {
                    row[detail.Ware.Name] = startViewCounter + detail.UnitQuantity;
                }

                //тепер заповнюємо перелік по підкатегоріям
                List<WareDocumentDetail> viewNotCategoryDetails = viewCategoryDetailsAll.Where(a => a.Ware.CategoryID != viewCategoryId).ToList();

                foreach (WareCategory category in viewCategories)
                {
                    string waresList = "";
                    List<WareDocumentDetail> details = detailsLogic.GetAllByWareCategory(startDate, endDate, category.ID, document.ID);
                    foreach (WareDocumentDetail detail in details)
                    {
                        waresList = waresList + detail.Ware.Name + ";\n";
                    }
                    row[category.Name] = waresList;
                }

                row["Коментарі"] = document.Description;

                table.Rows.Add(row);
            }

            DataGV.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            DataGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
            DataGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
            DataGV.AllowUserToResizeColumns = true;
            DataGV.AutoGenerateColumns = true;
            DataGV.DataSource = table;
            DataGV.Columns["Коментарі"].DisplayIndex = DataGV.Columns.Count - 1;
            DataGV.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.False;
            DataGV.Update();

            exportTable = table;
        }
Пример #8
0
        public int Recalculate(DateTime Month, int StructureObjectID)
        {
            int result = 1;
            StaffEmployeeLogic         employeesLogic        = new StaffEmployeeLogic(manager);
            StaffStructureObjectsLogic structureObjectsLogic = new StaffStructureObjectsLogic(manager);
            //List<Helpers.ItemIntValue> structureObjects = structureObjectsLogic.GetStructureObjectsHierarchy(false, StructureObjectID).ToList();
            //спочатку вибираємо працівників, що працюють в цьому відділі і всіх дочірніх відділах
            StaffEmployeePositionsLogic positionsLogic = new StaffEmployeePositionsLogic(manager);


            List <StaffEmployee> employees = positionsLogic.GetAllWithSubDepartments(StructureObjectID);;

            //проходимо покожному окремому працівнику
            foreach (StaffEmployee employee in employees)
            {
                //здійснюємо перерахунок по цьому працівнику

                decimal prevMonthSalary          = 0;
                decimal prevMonthExtraPercent    = 0;
                decimal currentMonthSalary       = 0;
                decimal currentMonthExtraPercent = 0;
                decimal documentsSum             = 0;

                //шукаємо документи до яких прикріплений даний працівник
                DocumentsLogic            documentsLogic            = new DocumentsLogic(manager);
                DocumentDetailsLogic      documentDetailsLogic      = new DocumentDetailsLogic(manager);
                DocumentStaffDetailsLogic documentStaffDetailsLogic = new DocumentStaffDetailsLogic(manager);
                List <WareDocument>       documents = documentsLogic.GetDocumentsByEmployeeID(employee.ID, Month, Month.AddMonths(1));

                //визначаємо суму документів
                foreach (WareDocument document in documents)
                {
                    documentsSum = documentsSum + document.DocumentSum;
                }


                //для цього спочатку шукаємо оклад працівника за ПОТОЧНИЙ місяць, якщо такий відсутній, то прирівнюємо до 0
                StaffEmployeeSalary currentSalary = this.GetByEmployeeID(employee.ID, Month);
                if (currentSalary != null)
                {
                    currentMonthSalary       = currentSalary.Salary;
                    currentMonthExtraPercent = currentSalary.ExtraPercent;
                    currentSalary.SumSale    = documentsSum;
                    currentSalary.SumSalary  = currentSalary.SumSale * (currentMonthExtraPercent / 100) + currentMonthSalary;
                }
                else
                {
                    //для цього спочатку шукаємо оклад працівника за попередній місяць, якщо такий відсутній, то прирівнюємо до 0
                    StaffEmployeeSalary prevSalary = this.GetByEmployeeID(employee.ID, Month.AddMonths(-1));
                    if (prevSalary != null)
                    {
                        prevMonthSalary       = prevSalary.Salary;
                        prevMonthExtraPercent = prevSalary.ExtraPercent;
                    }
                    currentMonthSalary       = prevMonthSalary;
                    currentMonthExtraPercent = prevMonthExtraPercent;
                    this.Create(Month, StructureObjectID, employee.ID, documentsSum, currentMonthExtraPercent, currentMonthSalary);
                }
            }

            return(result);
        }
Пример #9
0
        private void Fill()
        {
            int?selectedIndex = null;

            if (DataGV.SelectedRows.Count > 0)
            {
                selectedIndex = DataGV.SelectedRows[0].Index;
            }

            int?     documentTypeId = null;
            string   documentNumber = "";
            DateTime startDate      = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            DateTime?endDate        = null;
            decimal? documentSum    = null;

            if (documentFilterUC1.DocumentTypeID >= 0)
            {
                documentTypeId = documentFilterUC1.DocumentTypeID;
            }
            documentNumber = documentFilterUC1.DocumentNumber;
            startDate      = universalFilter1.StartDate == null ? startDate : Convert.ToDateTime(universalFilter1.StartDate);
            endDate        = universalFilter1.EndDate;
            documentSum    = documentFilterUC1.DocumentSum;



            SortableBindingList <DocumentView> view =
                new SortableBindingList <DocumentView>(documentsLogic.GetAllView(documentTypeId, documentNumber,
                                                                                 startDate, endDate, documentSum));



            //if (selectedIndex != null)
            //    if(DataGV.RowCount > selectedIndex)
            //     DataGV.Rows[Convert.ToInt32(selectedIndex)].Selected = true;

            DataTable table = new DataTable();


            table.Columns.Add("Дата", typeof(DateTime));
            table.Columns.Add("Адреса", typeof(string));

            WareCategoriesLogic categoriesLogic = new WareCategoriesLogic(manager);

            Compas.Logic.Documents.DocumentDetailsLogic detailsLogic = new DocumentDetailsLogic(manager);
            DocumentStaffDetailsLogic staffLogic = new DocumentStaffDetailsLogic(manager);
            WaresLogic waresLogic = new WaresLogic(manager);

            //Спочатку визначаємо яку категорію номенклатури нам необхідно проаналізувати
            int viewCategoryId = Convert.ToInt32(ViewCategoriesLUE.EditValue);

            List <WareCategory> categories = categoriesLogic.GetAllRoot().Where(a => a.ID != viewCategoryId).ToList();

            foreach (WareCategory category in categories)
            {
                table.Columns.Add(category.Name, typeof(string));
            }

            table.Columns.Add("Акт №", typeof(string));
            table.Columns.Add("Сума", typeof(decimal));
            table.Columns.Add("К-ть робіт", typeof(decimal));
            table.Columns.Add("К-ть виконавців", typeof(int));
            table.Columns.Add("К-ть на вик.", typeof(int));


            table.Columns.Add("Виконавець1", typeof(string));
            table.Columns.Add("Виконавець2", typeof(string));
            table.Columns.Add("Виконавець3", typeof(string));
            table.Columns.Add("Виконавець4", typeof(string));

            //Основні матеріали(номенклатура, включена в документ)

            List <WareCategory> viewCategories = categoriesLogic.GetAllChilds(viewCategoryId);

            //спочатку вкладені підкатегорії
            foreach (WareCategory category in viewCategories)
            {
                table.Columns.Add(category.Name, typeof(string));
            }
            //тоді номенклатурні одиниці даної категорії(без підкатегорій)
            List <Ware> wares = waresLogic.GetAll(viewCategoryId);

            //кожна номенклатурна одиниця - окрема колонка
            foreach (Ware ware in wares)
            {
                table.Columns.Add(ware.Name, typeof(decimal));
            }

            table.Columns.Add("Коментарі", typeof(string));



            categories = categoriesLogic.GetAllRoot().Where(a => a.ID != viewCategoryId).ToList();
            foreach (DocumentView document in view)
            {
                DataRow row = table.NewRow();
                row["Дата"]   = document.Date;
                row["Адреса"] = "Адреса надання послуги";
                row["Акт №"]  = document.Number;
                row["Сума"]   = document.DocumentSum;

                row["К-ть виконавців"] = 0;
                row["К-ть на вик."]    = 0;


                int counter = 0;
                //виводимо категорії по колонкам
                foreach (WareCategory category in categories)
                {
                    string detailsList = "";
                    List <WareDocumentDetail> details = detailsLogic.GetAllByWareCategory(startDate, endDate, category.ID, document.ID).Where(a => a.Ware.CategoryID != viewCategoryId).ToList();

                    foreach (WareDocumentDetail detail in details)
                    {
                        if (detailsList.Length > 0)
                        {
                            detailsList = detailsList + ";\n";
                        }
                        //стрічка містить перелік номенклатурних одиниць в межах категорії
                        detailsList = detailsList + detail.Ware.Name;
                        counter++;
                    }

                    if (row[category.Name] != null)
                    {
                        row[category.Name] = detailsList;
                    }
                }
                row["К-ть робіт"] = counter;



                //Працівники повязані з даним документом


                List <StaffEmployee> staffEmployees = staffLogic.GetStaffEmployeesByDocumentID(document.ID);

                counter = 1;


                string fullName = "";

                foreach (StaffEmployee employee in staffEmployees)
                {
                    fullName = employee.LastName + " " + employee.FirstName + " " + employee.MiddleName;

                    if (counter < 4)
                    {
                        row["Виконавець" + counter.ToString()] = fullName;
                    }
                    else
                    {
                        row["Виконавець" + counter.ToString()] = row["Виконавець" + counter.ToString()] + "; " + fullName;
                    }


                    counter = counter + 1;
                }


                //номенклатурні одиниці, пов'язані з документом

                string  viewCategoryDetailsList = "";
                decimal startViewCounter        = 0;
                List <WareDocumentDetail> viewCategoryDetailsAll = detailsLogic.GetAllByWareCategory(startDate, endDate, viewCategoryId, document.ID);
                List <WareDocumentDetail> viewCategoryDetails    = viewCategoryDetailsAll.Where(a => a.Ware.CategoryID == viewCategoryId).ToList();

                foreach (WareDocumentDetail detail in viewCategoryDetails)
                {
                    row[detail.Ware.Name] = startViewCounter + detail.UnitQuantity;
                }

                //тепер заповнюємо перелік по підкатегоріям
                List <WareDocumentDetail> viewNotCategoryDetails = viewCategoryDetailsAll.Where(a => a.Ware.CategoryID != viewCategoryId).ToList();


                foreach (WareCategory category in viewCategories)
                {
                    string waresList = "";
                    List <WareDocumentDetail> details = detailsLogic.GetAllByWareCategory(startDate, endDate, category.ID, document.ID);
                    foreach (WareDocumentDetail detail in details)
                    {
                        waresList = waresList + detail.Ware.Name + ";\n";
                    }
                    row[category.Name] = waresList;
                }

                row["Коментарі"] = document.Description;

                table.Rows.Add(row);
            }

            DataGV.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            DataGV.AutoSizeRowsMode          = DataGridViewAutoSizeRowsMode.DisplayedCells;
            DataGV.AutoSizeColumnsMode       = DataGridViewAutoSizeColumnsMode.DisplayedCells;
            DataGV.AllowUserToResizeColumns  = true;
            DataGV.AutoGenerateColumns       = true;
            DataGV.DataSource = table;
            DataGV.Columns["Коментарі"].DisplayIndex    = DataGV.Columns.Count - 1;
            DataGV.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.False;
            DataGV.Update();


            exportTable = table;
        }
Пример #10
0
        /// <summary>
        /// Збереження даних документу
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveBt_Click(object sender, EventArgs e)
        {
            if (dxValidationProvider1.Validate() == true)
            {

                if (ContractorLUE.EditValue != null)
                    document.ContractorID = Convert.ToInt32(ContractorLUE.EditValue);
                if (CurrencyLUE.EditValue != null)
                    document.CurrencyID = Convert.ToInt32(CurrencyLUE.EditValue);
                if (DateDE.EditValue != null)
                    document.Date = Convert.ToDateTime(DateDE.EditValue);

                document.Description = DescriptionTE.Text;
                document.Address = AddressTE.Text;
                document.Number = NumberTE.Text;
                if (DocumentTypeLUE.EditValue != null)
                    document.DocumentTypeID = Convert.ToInt32(DocumentTypeLUE.EditValue);
                if (FromObjectLUE.EditValue != null)
                    document.FromStructureObjectID = Convert.ToInt32(FromObjectLUE.EditValue);
                if (ToObjectLUE.EditValue != null)
                    document.ToStructureObjectD = Convert.ToInt32(ToObjectLUE.EditValue);

                int enterpriseId = Convert.ToInt32(EnterprisesCB.SelectedValue);

                int? teamId = null;
                if (TeamsLUE.EditValue != null)
                    teamId = Convert.ToInt32(TeamsLUE.EditValue);

                //перезаписуємо дані працівників
                documentsLogic.DeleteDocumentEmployees(document, employeesDetailsView);
                foreach (StaffEmployeeView item in employeesDetailsView)
                {

                    documentsLogic.SaveDocumentWithEmployees(document, item.Employee, teamId, mode);
                }

                if (cardId != null)
                    document.CardID = cardId;

                document.DocumentSum = documentSum;
                document.EnterpriseID = enterpriseId;
                if (mode == "new")
                {
                    document.CreatedDate = DateTime.Now;
                    document.CreatedUserID = Compas.Logic.Security.CurrentSecurityContext.Identity.ID;
                    int userId = Compas.Logic.Security.CurrentSecurityContext.Identity.ID;
                    Logic.Staff.StaffEmployeeLogic staffLogic = new Logic.Staff.StaffEmployeeLogic(manager);
                    StaffEmployee employee = staffLogic.GetByUserID(userId);
                    if (employee != null)
                        document.CreatedEmployeeID = employee.ID;

                    //foreach (WareDocumentDetail detail in documentDetailsNew)
                    //{
                    //    documentDetailsLogic.SaveDocumentDetail(detail);
                    //}
                    documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "new");

                }
                if (mode == "edit")
                {
                    documentDetailsLogic.DeleteAllForDocument(document.ID);
                    documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "edit");
                    //documentsLogic.
                }

                //якщо вказані дані про авто до перевіряємо чи дані вже існують
                string carNumber = CarNumberTE.Text;
                if (carNumber.Trim().Length > 0)
                {
                    CWCarsLogic carsLogic = new CWCarsLogic(manager);

                    CWCar car = null;
                    categoryId = null;
                    if (CarCategoriesCB.SelectedItem != null)
                    {
                        if (Convert.ToInt32(CarCategoriesCB.SelectedValue) > 0)
                            categoryId = Convert.ToInt32(CarCategoriesCB.SelectedValue);
                    }
                    List<CWCar> cars = carsLogic.GetAll(CarNumberTE.Text, modelId, brandId);
                    if (cars.Count > 0)
                    {
                        car = cars.FirstOrDefault();
                    }
                    else
                    {
                        car = carsLogic.Create(brandId, modelId, carNumber, categoryId);
                    }

                    if (ContractorLUE.EditValue != null)
                    {
                        CWContractorCarsLogic contractorCars = new CWContractorCarsLogic(manager);
                        contractorCars.Create(Convert.ToInt32(document.ContractorID), car);
                    }

                    DocumentCarsLogic documentCarsLogic = new DocumentCarsLogic(manager);
                    documentCarsLogic.Create(document, car);
                }

                //Зберігаємо зміни
                manager.Save();

                //Здійснюємо перерахунок залишків
                Compas.Logic.Wares.WareRemainsLogic remainsLogic = new Compas.Logic.Wares.WareRemainsLogic(manager);
                foreach (WareDocumentDetail detail in documentDetailsView)
                {
                    if (document.FromStructureObjectID != null)
                        remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.FromStructureObjectID, null);
                    if (document.ToStructureObjectD != null)
                        remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.ToStructureObjectD, null);
                }

                manager.Save();
                int documentId = document.ID;
                if (AddPaymentCB.Checked == true)
                {
                    DocumentPaymentData paymentForm = new DocumentPaymentData(documentId, document, cashRegister);
                    paymentForm.ShowDialog();
                }

                if (CloseAfterPayment == true)
                    this.Close();
                else
                {
                    //після збереження даного документу - позиції документа очищаються і форма готова для створення нового документа
                    CompasLogger.Add(String.Format("Start opening doc form"), CompasLogger.Level.Info);
                    manager = new ContextManager();

                    DetailsGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                    //FillPayments();
                    documentDetailsNew = new List<WareDocumentDetail>();
                    documentDetailsOld = new List<WareDocumentDetail>();
                    documentDetailsDeleted = new List<WareDocumentDetail>();
                    documentDetailsView = new List<WareDocumentDetail>();
                    employeesDetailsView = new List<StaffEmployeeView>();
                    documentsLogic = new DocumentsLogic(manager);
                    documentDetailsLogic = new DocumentDetailsLogic(manager);
                    if (mode == "new")
                    {
                        //створюємо документ в памяті
                        document = documentsLogic.CreateEmpty();
                    }
                    documentDetailsViewer.Clear();
                    FillDetails();
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Заповнюємо перелік позицій документу
        /// </summary>
        private void FillDetails()
        {
            CompasLogger.Add(String.Format("FillDetails1"), CompasLogger.Level.Info);
            int? selectedIndex = null;
            if (DetailsGV.SelectedRows.Count > 0)
            {
                selectedIndex = DetailsGV.SelectedRows[0].Index;
            }

            DocumentDetailsLogic detailsLogic = new DocumentDetailsLogic(manager);

            //documentDetailsView = documentDetailsNew;
            if (mode == "edit")
            {
                if (documentDetailsView.Count == 0)
                {
                    documentDetailsView = detailsLogic.GetAll(id);
                }

            }
            if ((mode == "new") & (documentDetailsView == null))
                documentDetailsView = new List<WareDocumentDetail>();

            if (selectedIndex != null)
                DetailsGV.Rows[Convert.ToInt32(selectedIndex)].Selected = true;

            CompasLogger.Add(String.Format("FillDetails2"), CompasLogger.Level.Info);
            //foreach (WareDocumentDetail a in documentDetailsNew)
            //{
            //    documentDetailsView.Add(a);
            //}
            //documentDetailsNew.Clear();

            //конвертуємо в список для перегляду і підраховуємо загальну суму документу
            //if (documentDetailsViewer == null)
            documentDetailsViewer = new List<DocumentDetailView>();
            documentSum = 0;
            decimal documentDuration = 0;
            WareTimeLimitsLogic timeLimitsLogic = new WareTimeLimitsLogic(manager);
            if (documentDetailsView.Count > 0)
            {
                foreach (WareDocumentDetail detail in documentDetailsView.OrderBy(a => a.ID))
                {
                    //if(documentDetailsViewer.Contains(
                    DocumentDetailView detailView = new DocumentDetailView(detail, manager);

                    documentDetailsViewer.Add(detailView);
                    documentSum = documentSum + Convert.ToDecimal(detail.EndPrice);

                    WareTimeLimit timeLimit = timeLimitsLogic.GetByWareID(detail.WareID);
                    if (timeLimit != null)
                    {
                        documentDuration = documentDuration + timeLimit.TimeLimit;
                    }

                }
            }

            CompasLogger.Add(String.Format("FillDetails3"), CompasLogger.Level.Info);
            DurationL.Text = documentDuration.ToString("n2");
            DocumentSumaL.Text = documentSum.ToString("n2");
            DetailsGV.AutoGenerateColumns = false;
            DetailsGV.DataSource = documentDetailsViewer;
            if (DetailsGV.Rows.Count == 0)
            {
                if(DetailsGV.SelectedRows.Count >0)
                    DetailsGV.SelectedRows[0].Selected = false;
            }
            //DetailsGV.Update();
            CompasLogger.Add(String.Format("FillDetails4"), CompasLogger.Level.Info);
        }
Пример #12
0
        /// <summary>
        /// Додавання позицій в документ по коду одиниці
        /// </summary>
        /// <param name="WareCode"></param>
        /// <returns></returns>
        private WareDocumentDetail AddDocumenDetailByWareCode(string WareCode)
        {
            DocumentDetailsLogic details = new DocumentDetailsLogic(manager);
            WareCodesLogic wareCodesLogic = new WareCodesLogic(manager);
            WareDocumentDetail result = null;
            Ware ware = wareCodesLogic.GetWareByCode(WareCode);
            if (ware != null)
            {
                int wareId = ware.ID;
                decimal unitQuantity = 1;
                decimal secondaryUnitQuantity = 0;
                decimal priceForUnit = 0;
                decimal discountForUnit = 0;
                decimal endSalePriceForUnit = 0;
                decimal endPrice = 0;

                int currencyId = Convert.ToInt32(CurrencyLUE.EditValue);
                int priceGroupID = 1;

                WareDocumentDetail DocumentDetail = new WareDocumentDetail();
                //створюємо новий запис в деталізації документа і повертаємо його
                DocumentDetail = details.CreateWithNoSave(wareId, unitQuantity, secondaryUnitQuantity,
                    priceForUnit, discountForUnit, endSalePriceForUnit, endPrice, currencyId, priceGroupID);
                documentDetailsView.Add(DocumentDetail);
                result = DocumentDetail;
                FillDetails();
            }
            else
            {
                MessageBox.Show("Товар з даним кодом не знайдено");
            }
            return result;
        }
Пример #13
0
        /// <summary>
        /// Збереження даних документу
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveBt_Click(object sender, EventArgs e)
        {
            if (dxValidationProvider1.Validate() == true)
            {
                if (ContractorLUE.EditValue != null)
                {
                    document.ContractorID = Convert.ToInt32(ContractorLUE.EditValue);
                }
                if (CurrencyLUE.EditValue != null)
                {
                    document.CurrencyID = Convert.ToInt32(CurrencyLUE.EditValue);
                }
                if (DateDE.EditValue != null)
                {
                    document.Date = Convert.ToDateTime(DateDE.EditValue);
                }

                document.Description = DescriptionTE.Text;
                document.Address     = AddressTE.Text;
                document.Number      = NumberTE.Text;
                if (DocumentTypeLUE.EditValue != null)
                {
                    document.DocumentTypeID = Convert.ToInt32(DocumentTypeLUE.EditValue);
                }
                if (FromObjectLUE.EditValue != null)
                {
                    document.FromStructureObjectID = Convert.ToInt32(FromObjectLUE.EditValue);
                }
                if (ToObjectLUE.EditValue != null)
                {
                    document.ToStructureObjectD = Convert.ToInt32(ToObjectLUE.EditValue);
                }

                int enterpriseId = Convert.ToInt32(EnterprisesCB.SelectedValue);

                int?teamId = null;
                if (TeamsLUE.EditValue != null)
                {
                    teamId = Convert.ToInt32(TeamsLUE.EditValue);
                }

                //перезаписуємо дані працівників
                documentsLogic.DeleteDocumentEmployees(document, employeesDetailsView);
                foreach (StaffEmployeeView item in employeesDetailsView)
                {
                    documentsLogic.SaveDocumentWithEmployees(document, item.Employee, teamId, mode);
                }

                if (cardId != null)
                {
                    document.CardID = cardId;
                }

                document.DocumentSum  = documentSum;
                document.EnterpriseID = enterpriseId;
                if (mode == "new")
                {
                    document.CreatedDate   = DateTime.Now;
                    document.CreatedUserID = Compas.Logic.Security.CurrentSecurityContext.Identity.ID;
                    int userId = Compas.Logic.Security.CurrentSecurityContext.Identity.ID;
                    Logic.Staff.StaffEmployeeLogic staffLogic = new Logic.Staff.StaffEmployeeLogic(manager);
                    StaffEmployee employee = staffLogic.GetByUserID(userId);
                    if (employee != null)
                    {
                        document.CreatedEmployeeID = employee.ID;
                    }

                    //foreach (WareDocumentDetail detail in documentDetailsNew)
                    //{
                    //    documentDetailsLogic.SaveDocumentDetail(detail);
                    //}
                    documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "new");
                }
                if (mode == "edit")
                {
                    documentDetailsLogic.DeleteAllForDocument(document.ID);
                    documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "edit");
                    //documentsLogic.
                }

                //якщо вказані дані про авто до перевіряємо чи дані вже існують
                string carNumber = CarNumberTE.Text;
                if (carNumber.Trim().Length > 0)
                {
                    CWCarsLogic carsLogic = new CWCarsLogic(manager);

                    CWCar car = null;
                    categoryId = null;
                    if (CarCategoriesCB.SelectedItem != null)
                    {
                        if (Convert.ToInt32(CarCategoriesCB.SelectedValue) > 0)
                        {
                            categoryId = Convert.ToInt32(CarCategoriesCB.SelectedValue);
                        }
                    }
                    List <CWCar> cars = carsLogic.GetAll(CarNumberTE.Text, modelId, brandId);
                    if (cars.Count > 0)
                    {
                        car = cars.FirstOrDefault();
                    }
                    else
                    {
                        car = carsLogic.Create(brandId, modelId, carNumber, categoryId);
                    }

                    if (ContractorLUE.EditValue != null)
                    {
                        CWContractorCarsLogic contractorCars = new CWContractorCarsLogic(manager);
                        contractorCars.Create(Convert.ToInt32(document.ContractorID), car);
                    }

                    DocumentCarsLogic documentCarsLogic = new DocumentCarsLogic(manager);
                    documentCarsLogic.Create(document, car);
                }


                //Зберігаємо зміни
                manager.Save();

                //Здійснюємо перерахунок залишків
                Compas.Logic.Wares.WareRemainsLogic remainsLogic = new Compas.Logic.Wares.WareRemainsLogic(manager);
                foreach (WareDocumentDetail detail in documentDetailsView)
                {
                    if (document.FromStructureObjectID != null)
                    {
                        remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.FromStructureObjectID, null);
                    }
                    if (document.ToStructureObjectD != null)
                    {
                        remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.ToStructureObjectD, null);
                    }
                }


                manager.Save();
                int documentId = document.ID;
                if (AddPaymentCB.Checked == true)
                {
                    DocumentPaymentData paymentForm = new DocumentPaymentData(documentId, document, cashRegister);
                    paymentForm.ShowDialog();
                }

                if (CloseAfterPayment == true)
                {
                    this.Close();
                }
                else
                {
                    //після збереження даного документу - позиції документа очищаються і форма готова для створення нового документа
                    CompasLogger.Add(String.Format("Start opening doc form"), CompasLogger.Level.Info);
                    manager = new ContextManager();

                    DetailsGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                    //FillPayments();
                    documentDetailsNew     = new List <WareDocumentDetail>();
                    documentDetailsOld     = new List <WareDocumentDetail>();
                    documentDetailsDeleted = new List <WareDocumentDetail>();
                    documentDetailsView    = new List <WareDocumentDetail>();
                    employeesDetailsView   = new List <StaffEmployeeView>();
                    documentsLogic         = new DocumentsLogic(manager);
                    documentDetailsLogic   = new DocumentDetailsLogic(manager);
                    if (mode == "new")
                    {
                        //створюємо документ в памяті
                        document = documentsLogic.CreateEmpty();
                    }
                    documentDetailsViewer.Clear();
                    FillDetails();
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Заповнюємо перелік позицій документу
        /// </summary>
        private void FillDetails()
        {
            CompasLogger.Add(String.Format("FillDetails1"), CompasLogger.Level.Info);
            int?selectedIndex = null;

            if (DetailsGV.SelectedRows.Count > 0)
            {
                selectedIndex = DetailsGV.SelectedRows[0].Index;
            }

            DocumentDetailsLogic detailsLogic = new DocumentDetailsLogic(manager);

            //documentDetailsView = documentDetailsNew;
            if (mode == "edit")
            {
                if (documentDetailsView.Count == 0)
                {
                    documentDetailsView = detailsLogic.GetAll(id);
                }
            }
            if ((mode == "new") & (documentDetailsView == null))
            {
                documentDetailsView = new List <WareDocumentDetail>();
            }

            if (selectedIndex != null)
            {
                DetailsGV.Rows[Convert.ToInt32(selectedIndex)].Selected = true;
            }

            CompasLogger.Add(String.Format("FillDetails2"), CompasLogger.Level.Info);
            //foreach (WareDocumentDetail a in documentDetailsNew)
            //{
            //    documentDetailsView.Add(a);
            //}
            //documentDetailsNew.Clear();

            //конвертуємо в список для перегляду і підраховуємо загальну суму документу
            //if (documentDetailsViewer == null)
            documentDetailsViewer = new List <DocumentDetailView>();
            documentSum           = 0;
            decimal             documentDuration = 0;
            WareTimeLimitsLogic timeLimitsLogic  = new WareTimeLimitsLogic(manager);

            if (documentDetailsView.Count > 0)
            {
                foreach (WareDocumentDetail detail in documentDetailsView.OrderBy(a => a.ID))
                {
                    //if(documentDetailsViewer.Contains(
                    DocumentDetailView detailView = new DocumentDetailView(detail, manager);

                    documentDetailsViewer.Add(detailView);
                    documentSum = documentSum + Convert.ToDecimal(detail.EndPrice);

                    WareTimeLimit timeLimit = timeLimitsLogic.GetByWareID(detail.WareID);
                    if (timeLimit != null)
                    {
                        documentDuration = documentDuration + timeLimit.TimeLimit;
                    }
                }
            }

            CompasLogger.Add(String.Format("FillDetails3"), CompasLogger.Level.Info);
            DurationL.Text                = documentDuration.ToString("n2");
            DocumentSumaL.Text            = documentSum.ToString("n2");
            DetailsGV.AutoGenerateColumns = false;
            DetailsGV.DataSource          = documentDetailsViewer;
            if (DetailsGV.Rows.Count == 0)
            {
                if (DetailsGV.SelectedRows.Count > 0)
                {
                    DetailsGV.SelectedRows[0].Selected = false;
                }
            }
            //DetailsGV.Update();
            CompasLogger.Add(String.Format("FillDetails4"), CompasLogger.Level.Info);
        }
Пример #15
0
        private void SaveBt_Click(object sender, EventArgs e)
        {
            if (dxValidationProvider1.Validate() == true)
            {

                DocumentDetailsLogic details = new DocumentDetailsLogic(manager);
                int wareId = (int)(WareLUE.EditValue);
                decimal unitQuantity = Convert.ToDecimal(UnitQuantityTB.Text);
                decimal secondaryUnitQuantity = Convert.ToDecimal(SecondaryUnitQuantityTB.Text);
                decimal priceForUnit = Convert.ToDecimal(SalePriceForUnitTB.Text);
                decimal discountForUnit = Convert.ToDecimal(DiscountForUnitTB.Text);
                decimal endSalePriceForUnit = Convert.ToDecimal(EndSalePriceForUnitTB.Text);
                decimal endPrice = Convert.ToDecimal(SalePriceTB.Text);
                int currencyId = Convert.ToInt32(CurrencyLUE.EditValue);
                int priceGroupID = Convert.ToInt32(PriceGroupsCBE.EditValue);

                //MessageBox.Show(wareId.ToString());
                if (mode == "new")
                {
                    //створюємо новий запис в деталізації документа і повертаємо його
                    DocumentDetail = details.CreateWithNoSave(wareId, unitQuantity, secondaryUnitQuantity,
                        priceForUnit, discountForUnit, endSalePriceForUnit, endPrice, currencyId, priceGroupID);
                    DocumentDetails.Add(DocumentDetail);

                }
                if (mode == "edit")
                {
                    //DocumentDetails.Remove(DocumentDetail);
                    DocumentDetail.UnitQuantity = unitQuantity;
                    DocumentDetail.SecondaryUnitQuantity = secondaryUnitQuantity;
                    DocumentDetail.PriceForUnit = priceForUnit;
                    DocumentDetail.DiscountForUnit = discountForUnit;
                    DocumentDetail.EndPriceForUnit = endSalePriceForUnit;
                    DocumentDetail.EndPrice = endPrice;
                    DocumentDetail.CurrencyID = currencyId;

                    //DocumentDetails.Add(DocumentDetail);

                }
                //manager.Save();

                this.Close();
            }
        }