Esempio n. 1
0
        private bool printSticker(Stickers sticker)
        {
            var stickersCreator = new StickersPrintingHelper(new List <Stickers>()
            {
                sticker
            });

            return(stickersCreator.Print());
        }
Esempio n. 2
0
        public bool SetPalletStatus(long stickerId, bool fullPallet)
        {
            var sticker = new Stickers() { ReadingId = stickerId };

            if (sticker.StartUnitsQuantity > 0)
                {
                return true;
                }

            if (fullPallet)
                {
                sticker.StartUnitsQuantity = sticker.UnitsQuantity;
                }
            else
                {
                if (sticker.Nomenclature.UnitsQuantityPerPallet > sticker.UnitsQuantity)
                    {
                    sticker.StartUnitsQuantity = sticker.Nomenclature.UnitsQuantityPerPallet;
                    }
                else
                    {
                    // �� �������� ����� �������� �� ������ ����. ���� �� ����, �������, ����� ���. ���������� ���� ������ ��������
                    sticker.StartUnitsQuantity = sticker.UnitsQuantity + 1;
                    }
                }

            return sticker.Write() == WritingResult.Success;
        }
Esempio n. 3
0
        public bool SetBarcode(string barcode, long stickerId, out bool recordWasAdded)
        {
            var sticker = new Stickers() { ReadingId = stickerId };
            var nomenclatureId = sticker.GetRef("Nomenclature");

            DataTable allWares;
            GetWares(barcode, SelectionFilters.All, out allWares);
            foreach (DataRow row in allWares.Rows)
                {
                var barcodeAlreadyAttached = (long)row["Id"] == nomenclatureId;
                if (barcodeAlreadyAttached)
                    {
                    recordWasAdded = false;
                    return true;
                    }
                }

            var barcodeRecord = new Barcodes() { Description = barcode };
            barcodeRecord.SetRef("Nomenclature", nomenclatureId);
            recordWasAdded = barcodeRecord.Write() == WritingResult.Success;
            return recordWasAdded;
        }
Esempio n. 4
0
        public bool PrintStickers(DataTable result)
        {
            List<Stickers> stickers = new List<Stickers>();
            foreach (DataRow row in result.Rows)
                {
                var sticker = new Stickers() { ReadingId = row[0] };
                stickers.Add(sticker);
                }

            printStickers(stickers);

            return true;
        }
Esempio n. 5
0
        public bool GetStickerData(long acceptanceId, long stickerId,
                out long nomenclatureId, out string nomenclatureDescription, out long trayId,
                out int totalUnitsQuantity, out int unitsPerBox,
                out long cellId, out string cellDescription, out bool currentAcceptance,
                out int wareBarcodesCount)
        {
            long stickerAcceptanceId;
            RowsStates rowState;
            long rowCellId;
            getAcceptanceId(stickerId, false, out stickerAcceptanceId, out rowState, out rowCellId);
            currentAcceptance = acceptanceId == stickerAcceptanceId;

            if (currentAcceptance)
                {
                var sticker = new Stickers() { ReadingId = stickerId };

                nomenclatureId = sticker.Nomenclature.Id;
                nomenclatureDescription = sticker.Nomenclature.Description;
                trayId = sticker.Tray.Id;
                unitsPerBox = sticker.Nomenclature.UnitsQuantityPerPack;
                totalUnitsQuantity = sticker.UnitsQuantity;

                cellId = rowCellId;
                cellDescription = FastInputDataCache.GetCashedData(typeof(Cells).Name).GetDescription(rowCellId);

                var q = DB.NewQuery("select count(*) from Barcodes where MarkForDeleting = 0 and Nomenclature = @Ware");
                q.AddInputParameter("Ware", nomenclatureId);

                wareBarcodesCount = q.SelectInt32();
                if (wareBarcodesCount == 0)
                    {
                    var isKeg = !sticker.Nomenclature.BoxType.Empty
                                && sticker.Nomenclature.UnitsQuantityPerPallet > 0
                                && sticker.Nomenclature.UnitsQuantityPerPack == 1
                                && sticker.Nomenclature.ShelfLife > 0;

                    if (isKeg)
                        {
                        // � ���� �� ����� ���� �����-����
                        wareBarcodesCount = -1;
                        }
                    }
                }
            else
                {
                Cells palletCell = findPalletCell(stickerId);
                cellId = palletCell.Id;
                cellDescription = palletCell.Description;

                nomenclatureDescription = string.Empty;
                trayId = 0;
                unitsPerBox = 0;
                nomenclatureId = 0;
                totalUnitsQuantity = 0;
                wareBarcodesCount = 0;
                }

            return true;
        }
Esempio n. 6
0
        public bool GetPickingTask(long documentId, long palletId, int predefinedTaskLineNumber, int currentLineNumber,
            out long stickerId, out long wareId, out string wareDescription,
            out long cellId, out string cellDescription,
            out long partyId, out DateTime productionDate,
            out int unitsPerBox, out int unitsToPick,
            out int lineNumber)
        {
            const string sql =
            @"
            select top 1 cap.[State],
            task.PalletCode stickerId, task.LineNumber,
            task.Nomenclature wareId, rtrim(n.[description]) wareDescription,
            task.StartCell cellId, ISNULL(rtrim(c.[Description]), '') cellDescription,
            task.Party partyId, isnull(p.DateOfManufacture, '0001-01-01') productionDate,
            n.UnitsQuantityPerPack unitsPerBox, task.PlanValue unitsToPick

            from SubMovingNomenclatureInfo task
            join Nomenclature n on n.Id = task.Nomenclature
            left join Cells c on c.Id = task.StartCell
            left join Parties p on p.Id = task.Party
            join Moving cap on cap.Id = task.IdDoc

            where IdDoc = @IdDoc and (RowState = @PlannedPickingState or (RowState = @ProcessingState and Employee = @userId))
            and (@currentLineNumber = 0 or task.LineNumber = @currentLineNumber)
            and (@nomenclature = 0 or task.Nomenclature = @nomenclature)
            order by [LineNumber]";
            var q = DB.NewQuery(sql);
            q.AddInputParameter("IdDoc", documentId);
            q.AddInputParameter("PlannedPickingState", RowsStates.PlannedPicking);
            q.AddInputParameter("ProcessingState", RowsStates.Processing);
            q.AddInputParameter("userId", getUserId());
            q.AddInputParameter("currentLineNumber", predefinedTaskLineNumber);

            var nomenclatureId = 0L;
            if (palletId != 0)
                {
                var sticker = new Stickers() { ReadingId = palletId };
                nomenclatureId = sticker.GetRef("Nomenclature");
                }
            q.AddInputParameter("nomenclature", nomenclatureId);

            stickerId = wareId = cellId = partyId = unitsToPick = unitsPerBox = lineNumber = 0;
            wareDescription = cellDescription = string.Empty;
            productionDate = DateTime.MinValue;

            // � ���������� ����� ������������� �������� ������ � ���������� �������� palletId, � ����� � �� �������������
            using (var locker = new DatabaseObjectLocker(typeof(Moving), documentId))
                {
                if (!locker.LockForCurrentPdtThread()) return false;

                var qResult = q.SelectRow();

                if (qResult == null)
                    {
                    return true;
                    }

                var documentState = (StatesOfDocument)Convert.ToInt32(qResult["State"]);
                if (documentState == StatesOfDocument.Planned)
                    {
                    var moving = new Moving() { ReadingId = documentId };
                    moving.State = StatesOfDocument.Processing;
                    moving.Write();
                    }

                stickerId = Convert.ToInt64(qResult["stickerId"]);
                wareId = Convert.ToInt64(qResult["wareId"]);
                wareDescription = qResult["wareDescription"].ToString();
                cellId = Convert.ToInt64(qResult["cellId"]);
                cellDescription = qResult["cellDescription"].ToString();
                partyId = Convert.ToInt64(qResult["partyId"]);
                productionDate = (DateTime)qResult["productionDate"];
                unitsPerBox = Convert.ToInt32(qResult["unitsPerBox"]);
                unitsToPick = Convert.ToInt32(qResult["unitsToPick"]);
                lineNumber = Convert.ToInt32(qResult["LineNumber"]);

                if (currentLineNumber > 0)
                    {
                    documentId.SetRowState(typeof(Moving), currentLineNumber, RowsStates.PlannedPicking);
                    }
                documentId.SetRowState(typeof(Moving), lineNumber, RowsStates.Processing, employee: getUserId());
                }
            return true;
        }
Esempio n. 7
0
        public bool GetPalletBalance(long palletId,
            out long nomenclatureId,
            out string nomenclatureDescription,
            out long trayId, out long linerId, out int linersAmount,
            out int unitsPerBox, out long cellId, out string cellDescription, out long previousPalletCode, out DateTime productionDate, out long partyId,
            out int totalUnitsQuantity,
            out int traysCount)
        {
            partyId = trayId = linerId = cellId = previousPalletCode = totalUnitsQuantity = unitsPerBox = linersAmount = traysCount = 0;
            productionDate = DateTime.MinValue;
            cellDescription = string.Empty;

            GoodsRows goodsRows = getPalletBalance(palletId);

            var sticker = new Stickers() { ReadingId = palletId };
            nomenclatureId = sticker.Nomenclature.Id;
            nomenclatureDescription = sticker.Nomenclature.Description;
            unitsPerBox = sticker.Nomenclature.UnitsQuantityPerPack;

            if (goodsRows.TrayRow != null)
                {
                trayId = Convert.ToInt64(goodsRows.TrayRow[GoodsRows.NOMENCLATURE]);
                traysCount = Convert.ToInt32(goodsRows.TrayRow[GoodsRows.QUANTITY]);
                }

            if (goodsRows.LinerRow != null)
                {
                linerId = Convert.ToInt64(goodsRows.LinerRow[GoodsRows.NOMENCLATURE]);
                linersAmount = Convert.ToInt32(goodsRows.LinerRow[GoodsRows.QUANTITY]);
                }

            if (goodsRows.WareRow != null)
                {
                cellId = Convert.ToInt64(goodsRows.WareRow[GoodsRows.CELL]);
                cellDescription = goodsRows.WareRow["CellDescription"].ToString();
                var productionDateObj = goodsRows.WareRow["ProductionDate"];
                productionDate = productionDateObj.IsNull() ? DateTime.MinValue : (DateTime)productionDateObj;
                partyId = Convert.ToInt64(goodsRows.WareRow["Party"]);
                totalUnitsQuantity = Convert.ToInt32(goodsRows.WareRow[GoodsRows.QUANTITY]);
                }

            var q = DB.NewQuery("select top 1 relation.PreviousPallet from dbo.GetPalletsRelations ('0001-01-01', @palletId, 0) relation");
            q.AddInputParameter("palletId", palletId);
            previousPalletCode = q.SelectInt64();

            return true;
        }
Esempio n. 8
0
        private void openPalletButton_ItemClick(object sender, ItemClickEventArgs e)
        {
            var currentRow = nomenclatureView.GetFocusedDataRow();
            if (currentRow != null)
                {
                var sticker = new Stickers() { ReadingId = currentRow[Document.NomenclatureCode] };
                if (sticker.Empty) return;

                UserInterface.Current.ShowItem(sticker);
                }
        }
Esempio n. 9
0
        public bool CreateNewSticker(long wareId, DateTime expirationDate, int unitsQuantity, int boxesCount, long linerId, int linersCount, out long newStickerId)
        {
            var party = Parties.FindByExpirationDate(wareId, expirationDate);

            if (party.IsNull() || party.Empty)
                {
                newStickerId = 0;
                return false;
                }

            var nomenclature = new Nomenclature() { ReadingId = wareId };
            var sticker = new Stickers()
                {
                    Nomenclature = nomenclature,
                    Party = party,
                    UnitsQuantity = unitsQuantity,
                    Quantity = boxesCount,
                    ReleaseDate = party.DateOfManufacture,
                    ExpiryDate = party.TheDeadlineSuitability,
                    AcceptionDate = DateTime.Now,
                    Liner = new Nomenclature() { ReadingId = linerId },
                    LinersQuantity = linersCount
                };

            // ���������������, ��� ������� �������
            sticker.StartUnitsQuantity = nomenclature.UnitsQuantityPerPallet > unitsQuantity
                ? nomenclature.UnitsQuantityPerPallet
                : unitsQuantity;

            sticker.Write();
            newStickerId = sticker.Id;

            var stickerExists = newStickerId > 0;

            if (stickerExists)
                {
                printStickers(new List<Stickers>() { sticker });
                }

            return stickerExists;
        }
Esempio n. 10
0
 private bool printSticker(Stickers sticker)
 {
     var stickersCreator = new StickersPrintingHelper(new List<Stickers>() { sticker });
     return stickersCreator.Print();
 }
Esempio n. 11
0
 private Stickers createSticker(Nomenclature nomenclature, Parties party, int packsQuantity, int unitsQuantity, long trayId, int startUnitsQuantity)
 {
     var sticker = new Stickers();
     sticker.Nomenclature = nomenclature;
     sticker.Quantity = packsQuantity;
     sticker.UnitsQuantity = unitsQuantity;
     sticker.Driver = Driver;
     if (trayId > 0)
         {
         sticker.SetRef("Tray", trayId);
         }
     sticker.AcceptionDate = Date;
     sticker.StartUnitsQuantity = startUnitsQuantity;
     sticker.ReleaseDate = party.DateOfManufacture;
     sticker.ExpiryDate = party.TheDeadlineSuitability;
     sticker.Party = party;
     if (sticker.Write() != WritingResult.Success)
         {
         return null;
         }
     return sticker;
 }
Esempio n. 12
0
        private void addWaresFromSticker(Stickers sticker)
        {
            Cells cell = sticker.Nomenclature.IsKeg() ? Consts.RedemptionCell : new Cells();

            addWareRow(sticker, cell, sticker.Nomenclature, sticker.UnitsQuantity, sticker.Party.Id);
            addWareRow(sticker, cell, sticker.Nomenclature.BoxType, sticker.Quantity, 0);
            addWareRow(sticker, cell, sticker.Tray, 1, 0);
        }
Esempio n. 13
0
        private void addWareRow(Stickers sticker, Cells cell, Nomenclature nomenclature, int quantity, long partyId)
        {
            if (quantity > 0 && !nomenclature.Empty)
                {
                var row = NomenclatureInfo.GetNewRow(this);

                row[Nomenclature] = nomenclature.Id;
                row[NomenclaturePlan] = quantity;
                row[NomenclatureParty] = partyId;
                row[NomenclatureCode] = sticker.Id;
                row[NomenclatureCell] = cell.Id;

                row.AddRowToTable(this);
                }
        }
Esempio n. 14
0
        private void addPlanDocument(long acceptancePlanId)
        {
            var row = Plans.GetNewRow(this);
            row[AcceptancePlan] = acceptancePlanId;
            row.AddRowToTable(this);

            var acceptancePlan = new AcceptancePlan() { ReadingId = acceptancePlanId };
            foreach (DataRow stickerRow in acceptancePlan.Stickers.Rows)
                {
                var sticker = new Stickers() { ReadingId = stickerRow[acceptancePlan.Sticker] };
                addWaresFromSticker(sticker);
                }
        }
Esempio n. 15
0
        internal bool WriteStickerFact(long stickerId, long cellId, long previousStickerId, long trayId, long linerId, int linersQuantity, int packsCount, int unitsCount)
        {
            var goodsRows = findStickerRows(stickerId);

            var isReturnFromHaul = Contractor.Empty;
            if (isReturnFromHaul)
                {
                var sticker = new Stickers() { ReadingId = stickerId };

                if (goodsRows.WareRow == null)
                    {
                    goodsRows.WareRow = addNewNomenclatureRow(stickerId, sticker.GetRef("Nomenclature"));
                    goodsRows.WareRow[NomenclatureParty] = sticker.GetRef("Party");
                    }

                if (packsCount > 0 && goodsRows.BoxRow == null)
                    {
                    var packId = sticker.Nomenclature.GetRef("BoxType");
                    if (packId > 0)
                        {
                        goodsRows.BoxRow = addNewNomenclatureRow(stickerId, packId);
                        }
                    }
                }

            setFactOnRow(goodsRows.WareRow, unitsCount, cellId, false);
            goodsRows.WareRow[PreviousPalletCode] = previousStickerId;

            if (goodsRows.BoxRow != null)
                {
                setFactOnRow(goodsRows.BoxRow, packsCount, cellId, true);
                }

            if (linersQuantity > 0 && linerId > 0)
                {
                if (goodsRows.LinerRow == null)
                    {
                    goodsRows.LinerRow = addNewNomenclatureRow(stickerId, linerId);
                    }
                setFactOnRow(goodsRows.LinerRow, linersQuantity, cellId, true);
                }

            int traysQuantity = trayId > 0 ? 1 : 0;
            if (goodsRows.TrayRow == null && traysQuantity > 0)
                {
                goodsRows.TrayRow = addNewNomenclatureRow(stickerId, trayId);
                }
            if (goodsRows.TrayRow != null)
                {
                setFactOnRow(goodsRows.TrayRow, traysQuantity, cellId, true);
                }

            SetSubtableModified(NomenclatureInfo.TableName);

            var result = Write() == WritingResult.Success;

            return result;
        }
Esempio n. 16
0
        public bool WriteMovementResult(long documentId, DataTable resultTable)
        {
            var q = DB.NewQuery("select max(LineNumber) lastRowNumber from SubMovingNomenclatureInfo where IdDoc = @IdDoc");
            q.AddInputParameter("IdDoc", documentId);
            var lastLineNumber = q.SelectInt64();

            var document = new Moving();
            var currentTime = SystemConfiguration.ServerDateTime;

            // ��� ������ ������ ���� � ���� �����, �.�. ����� ��������� ������� ����� ���������� � ��������, ��� ��� �� null
            var docTable = document.NomenclatureInfo;

            var palletCode = Convert.ToInt64(resultTable.Rows[0][document.PalletCode.ColumnName]);

            new BoxesFinder(resultTable, palletCode);

            var userId = getUserId();
            for (int rowIndex = 0; rowIndex < resultTable.Rows.Count; rowIndex++)
                {
                var sourceRow = resultTable.Rows[rowIndex];
                var newRow = docTable.GetNewRow(document);
                newRow[document.RowState] = (int)RowsStates.Completed;
                newRow[document.RowDate] = currentTime;

                var isTare = rowIndex != 0;
                if (!isTare)
                    {
                    var sticker = new Stickers() { ReadingId = palletCode };
                    newRow[document.Party] = sticker.GetRef("Party");
                    }

                newRow[document.Nomenclature] = Convert.ToInt64(sourceRow[document.Nomenclature.ColumnName]);
                newRow[document.PlanValue] = Convert.ToDecimal(sourceRow[document.PlanValue.ColumnName]);
                newRow[document.FactValue] = Convert.ToDecimal(sourceRow[document.FactValue.ColumnName]);

                newRow[document.PalletCode] = palletCode;

                newRow[document.StartCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[document.StartCodeOfPreviousPallet.ColumnName]);
                newRow[document.FinalCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[document.FinalCodeOfPreviousPallet.ColumnName]);

                newRow[document.StartCell] = Convert.ToInt64(sourceRow[document.StartCell.ColumnName]);
                newRow[document.FinalCell] = Convert.ToInt64(sourceRow[document.FinalCell.ColumnName]);
                newRow[document.Employee] = userId;
                newRow[CONSTS.LINE_NUMBER_COLUMN_NAME] = lastLineNumber + rowIndex + 1;
                newRow.AddRowToTable(document);
                }

            var rowsToInsert = document.NomenclatureInfo;

            q = DB.NewQuery(@"insert into subMovingNomenclatureInfo([IdDoc],[LineNumber],[PalletCode],[Nomenclature],
            [PlanValue],[FactValue],[RowState],[RowDate],
            [StartCodeOfPreviousPallet] ,[FinalCodeOfPreviousPallet],
            [StartCell],[FinalCell], [Party], [Employee])

            select @IdDoc, [LineNumber],[PalletCode],[Nomenclature],
            [PlanValue],[FactValue],[RowState],[RowDate],
            [StartCodeOfPreviousPallet] ,[FinalCodeOfPreviousPallet],
            [StartCell],[FinalCell], [Party], [Employee]
            from @table");

            q.AddInputTVPParameter("table", rowsToInsert, "dbo.tvp_Moving_NomenclatureInfo");
            q.AddInputParameter("IdDoc", documentId);

            q.Execute();

            return q.ThrowedException == null;
        }
Esempio n. 17
0
        public bool WriteStickerFact(long acceptanceId, long stickerId, bool palletChanged, long cellId, long previousStickerId, long trayId, long linerId,
            int linersQuantity, int packsCount, int unitsCount)
        {
            if (palletChanged)
                {
                var sticker = new Stickers() { ReadingId = stickerId };
                sticker.Tray = new Nomenclature() { ReadingId = trayId };
                sticker.Liner = new Nomenclature() { ReadingId = linerId };
                sticker.LinersQuantity = linersQuantity;
                sticker.Quantity = packsCount;
                sticker.UnitsQuantity = unitsCount;

                if (sticker.Write() != WritingResult.Success)
                    {
                    return false;
                    }
                }

            var acceptance = new AcceptanceOfGoods() { ReadingId = acceptanceId };

            var result = acceptance.WriteStickerFact(stickerId, cellId, previousStickerId, trayId, linerId, linersQuantity, packsCount, unitsCount);
            return result;
        }
Esempio n. 18
0
        private bool writeInventoryResult(long documentId, DataTable resultTable, bool resultOfOnePallet)
        {
            if (resultTable.Rows.Count == 0) return true;

            var q = DB.NewQuery("select max(LineNumber) lastRowNumber from subInventoryNomenclatureInfo where IdDoc = @IdDoc");
            q.AddInputParameter("IdDoc", documentId);
            var lastLineNumber = q.SelectInt64();

            var inventory = new Inventory();
            var currentTime = SystemConfiguration.ServerDateTime;

            // ��� ������ ������ ���� � ���� �����, �.�. ����� ��������� ������� ����� ���������� � ��������, ��� ��� �� null
            var docTable = inventory.NomenclatureInfo;

            var palletCode = 0L;
            var firstDataRow = resultTable.Rows[0];
            if (resultOfOnePallet)
                {
                palletCode = Convert.ToInt64(firstDataRow[inventory.PalletCode.ColumnName]);
                new BoxesFinder(resultTable, palletCode);
                }

            long startCodeOfPreviousPallet = 0;
            long finalCodeOfPreviousPallet = 0;

            for (int rowIndex = 0; rowIndex < resultTable.Rows.Count; rowIndex++)
                {
                var sourceRow = resultTable.Rows[rowIndex];
                var newRow = docTable.GetNewRow(inventory);
                newRow[inventory.RowState] = (int)RowsStates.Completed;
                newRow[inventory.RowDate] = currentTime;

                if (resultOfOnePallet)
                    {
                    var isTare = rowIndex != 0;
                    if (!isTare)
                        {
                        var sticker = new Stickers() { ReadingId = palletCode };
                        newRow[inventory.Party] = sticker.GetRef("Party");

                        startCodeOfPreviousPallet = Convert.ToInt64(sourceRow[inventory.StartCodeOfPreviousPallet.ColumnName]);
                        finalCodeOfPreviousPallet = Convert.ToInt64(sourceRow[inventory.FinalCodeOfPreviousPallet.ColumnName]);
                        }
                    }
                else
                    {
                    newRow[inventory.Party] = Convert.ToInt64(sourceRow[inventory.Party.ColumnName]);
                    }

                newRow[inventory.Nomenclature] = Convert.ToInt64(sourceRow[inventory.Nomenclature.ColumnName]);
                newRow[inventory.PlanValue] = Convert.ToDecimal(sourceRow[inventory.PlanValue.ColumnName]);
                newRow[inventory.FactValue] = Convert.ToDecimal(sourceRow[inventory.FactValue.ColumnName]);

                newRow[inventory.PalletCode] = Convert.ToInt64(sourceRow[inventory.PalletCode.ColumnName]);

                newRow[inventory.StartCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[inventory.StartCodeOfPreviousPallet.ColumnName]);
                newRow[inventory.FinalCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[inventory.FinalCodeOfPreviousPallet.ColumnName]);

                newRow[inventory.StartCell] = Convert.ToInt64(sourceRow[inventory.StartCell.ColumnName]);
                newRow[inventory.FinalCell] = Convert.ToInt64(sourceRow[inventory.FinalCell.ColumnName]);

                newRow[CONSTS.LINE_NUMBER_COLUMN_NAME] = lastLineNumber + rowIndex + 1;
                newRow.AddRowToTable(inventory);
                }

            if (resultOfOnePallet)
                {
                // ���� ��-�� �������� �������� ���� ������� � �����-������ ������ ���, �� ����� ��������
                q = DB.NewQuery(@"
            select @palet PalletCode, 0 StartCodeOfPreviousPallet, 0 FinalCodeOfPreviousPallet, Nomenclature, Party, Quantity PlanValue, Cell StartCell, 0 FinalCell
            from dbo.GetStockBalance('0001-01-01', 0, 0, 2, 0, @palet) balance
            where Cell <> @cell

            union all

            select rel.Pallet PalletCode, case when rel.Quantity > 0 then rel.PreviousPallet else 0 end StartCodeOfPreviousPallet,
            case when rel.Quantity > 0 then 0 else rel.PreviousPallet end FinalCodeOfPreviousPallet, 0 Nomenclature, 0 Party,
            0 PlanValue, @emptyCell StartCell, @emptyCell FinalCell
            from dbo.GetPalletsRelations('0001-01-01', @palet, 0) rel
            where rel.PreviousPallet <> @startPrevPalet and @palet > 0

            union all

            select rel.Pallet PalletCode, case when rel.Quantity > 0 then @finishPrevPalet else 0 end StartCodeOfPreviousPallet,
            case when rel.Quantity > 0 then 0 else @finishPrevPalet end FinalCodeOfPreviousPallet, 0 Nomenclature, 0 Party,
            0 PlanValue, @emptyCell StartCell, @emptyCell FinalCell
            from dbo.GetPalletsRelations('0001-01-01', 0, @finishPrevPalet) rel
            where rel.Pallet <> @palet and @finishPrevPalet > 0
            ");
                q.AddInputParameter("palet", palletCode);
                q.AddInputParameter("emptyCell", Consts.EmptyCell.Id);
                q.AddInputParameter("cell", firstDataRow[inventory.StartCell.ColumnName]);
                q.AddInputParameter("startPrevPalet", startCodeOfPreviousPallet);
                q.AddInputParameter("finishPrevPalet", finalCodeOfPreviousPallet);
                var addTable = q.SelectToTable();

                var emptyCell = Consts.EmptyCell.Id;
                lastLineNumber = Convert.ToInt64(docTable.Rows[docTable.Rows.Count - 1][CONSTS.LINE_NUMBER_COLUMN_NAME]);
                for (int rowIndex = 0; rowIndex < addTable.Rows.Count; rowIndex++)
                    {
                    var sourceRow = addTable.Rows[rowIndex];

                    var newRow = docTable.GetNewRow(inventory);
                    newRow[inventory.RowState] = (int)RowsStates.Completed;
                    newRow[inventory.RowDate] = currentTime;
                    newRow[inventory.Party] = Convert.ToInt64(sourceRow[inventory.Party.ColumnName]);

                    newRow[inventory.Nomenclature] = Convert.ToInt64(sourceRow[inventory.Nomenclature.ColumnName]);
                    newRow[inventory.PlanValue] = Convert.ToDecimal(sourceRow[inventory.PlanValue.ColumnName]);
                    newRow[inventory.FactValue] = 0M;

                    newRow[inventory.PalletCode] = Convert.ToInt64(sourceRow[inventory.PalletCode.ColumnName]);

                    newRow[inventory.StartCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[inventory.StartCodeOfPreviousPallet.ColumnName]);
                    newRow[inventory.FinalCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[inventory.FinalCodeOfPreviousPallet.ColumnName]);

                    newRow[inventory.StartCell] = Convert.ToInt64(sourceRow[inventory.StartCell.ColumnName]);
                    newRow[inventory.FinalCell] = Convert.ToInt64(sourceRow[inventory.FinalCell.ColumnName]);

                    newRow[CONSTS.LINE_NUMBER_COLUMN_NAME] = lastLineNumber + rowIndex + 1;
                    newRow.AddRowToTable(inventory);
                    }
                }

            return appendRowsToInventory(documentId, docTable);
        }