Пример #1
0
 public void OrderSet(fmCOrder value)
 {
     SetPropertyValue <fmCOrder>("Order", ref _Order, value);
     SubjectSet(value.Subject);
     foreach (var oper in Operations)
     {
         oper.Order = value;
     }
 }
 protected override void OnChanged(string propertyName, object oldValue, object newValue)
 {
     base.OnChanged(propertyName, oldValue, newValue);
     if (propertyName == "Order")
     {
         fmCOrder order = newValue as fmCOrder;
         if (order != null)
         {
             CodeSet("тог." + order.Code + ".о1");
             Journal.CodeSet(Code);
         }
     }
 }
Пример #3
0
 public void OrdersAdd(fmCOrder order)
 {
     order.SourceType             = this.SourceType;
     order.SourceDeal             = this.SourceDeal;
     order.SourceOther            = this.SourceOther;
     order.SourceParty            = this.SourceParty;
     order.AnalitycWorkType       = this.AnalitycWorkType;
     order.AnalitycFinanceSource  = this.AnalitycFinanceSource;
     order.AnalitycAVT            = this.AnalitycAVT;
     order.AnalitycBigCustomer    = this.AnalitycBigCustomer;
     order.AnalitycCoperatingType = this.AnalitycCoperatingType;
     order.AnalitycFedProg        = this.AnalitycFedProg;
     order.AnalitycMilitary       = this.AnalitycMilitary;
     order.AnalitycOrderSource    = this.AnalitycOrderSource;
     order.AnalitycRegion         = this.AnalitycRegion;
     order.Manager = this.Manager;
     order.ManagerPlanDepartment = this.ManagerPlanDepartment;
 }
 protected override void ProcessCell(String sheet_name, Int32 row, Int32 column, String type, String value)
 {
     //            System.Console.WriteLine("{0}({1},{2}) {3}:'{4}'", sheet, row, column, type, value);
     //            if (sheet_name != "БСР")
     if (sheet_name == "БСР" && row == 2 && column == 12)
     {
         fmCOrder order = ObjectSpace.FindObject <fmCOrder>(
             new BinaryOperator("Code", value));
         if (order == null || order.Subject != TargetDoc.Subject)
         {
             throw new InvalidDataException("Заказ неверный или тема не соответствует заказу");
         }
         TargetDoc.Order = order;
         return;
     }
     if (sheet_name == "БСР" && row == 2 && column == 16)
     {
         TargetDoc.Valuta = Valutas.FirstOrDefault(x => x.Code == ValutaCodeConvert(value));
         foreach (var line in TargetDoc.SubLines)
         {
             line.Valuta = TargetDoc.Valuta;
         }
     }
     if (sheet_name == "БСР" && row == 4 && column == 9)
     {
         BeginYear = (Int16)(Int32.Parse(value) - 1);
     }
     if (sheet_name == "БСР" && row == 4 && column == 16)
     {
         TargetDoc.VatRate = VatRates.FirstOrDefault(x => x.Code == VatCodeConvert(value));
         foreach (var line in TargetDoc.SubLines)
         {
             line.VatRate = TargetDoc.VatRate;
         }
     }
     foreach (var line in TargetDoc.SubLines)
     {
         if (line.LineName == sheet_name)
         {
             LoadTableCell(line, row, column, type, value);
             break;
         }
     }
 }
Пример #5
0
            public void Import(IObjectSpace os, String file_name)
            {
                DelimitedFileEngine engine = new DelimitedFileEngine(typeof(Tr));

                engine.Options.IgnoreFirstLines = 1;
                Tr[] records = (Tr[])engine.ReadFile(file_name);
                IList <fmÑOrderAnalitycFinanceSource> type_refs = os.GetObjects <fmÑOrderAnalitycFinanceSource>();

                foreach (Tr rec in records)
                {
                    fmCOrder order = os.GetObjects <fmCOrder>(new BinaryOperator("Code", rec.Code)).First();
                    if (rec.OrderType == "ÊÏ")
                    {
                        order.AnalitycFinanceSource = type_refs.First(x => x.Code == "Ïð.êîììåð.");
                    }
                    if (rec.OrderType == "×Ï")
                    {
                        order.AnalitycFinanceSource = type_refs.First(x => x.Code == "×èñò.Ïðèáûëü");
                    }
                }
            }
Пример #6
0
        public void Import(IObjectSpace os, String file_name)
        {
            FileHelperEngine <DealDataImport> engine = new FileHelperEngine <DealDataImport>();

            engine.Options.IgnoreFirstLines = 1;
            engine.Options.IgnoreEmptyLines = true;
            //            DealDataImport[] deal_data = engine.ReadStream(reader);
            DealDataImport[]        deal_data      = engine.ReadFile(file_name);
            IList <fmCOrder>        orders         = new List <fmCOrder>();
            IList <crmStage>        stages         = new List <crmStage>();
            IList <crmDeliveryUnit> delivery_units = new List <crmDeliveryUnit>();
            IList <crmDeliveryItem> delivery_items = new List <crmDeliveryItem>();
            IList <crmPaymentUnit>  payment_units  = new List <crmPaymentUnit>();
            IList <crmPaymentItem>  payment_items  = new List <crmPaymentItem>();
            IList <csMaterial>      materials      = os.GetObjects <csMaterial>();

            foreach (DealDataImport record in deal_data)
            {
                fmCOrder        order         = null;
                crmStage        stage         = null;
                crmDeliveryUnit delivery_unit = null;
                crmDeliveryItem delivery_item = null;
                crmPaymentUnit  payment_unit  = null;
                crmPaymentItem  payment_item  = null;
                if (String.IsNullOrEmpty(record.StageCode))
                {
                    throw new ArgumentException("Stage Code is Empty", "StageCode");
                }
                if (record.StageCode.Substring(0, 3) == "Adv")
                {
                    stage = StageStructure.FirstStage;
                }
                else
                {
                    stage = StageStructure.Stages.FirstOrDefault(x => x.Code == record.StageCode);
                    if (stage == null)
                    {
                        stage      = StageStructure.FirstStage.SubStagesCreate();
                        stage.Code = record.StageCode;
                    }
                    if (!stages.Contains(stage))
                    {
                        stage.StageType      = Contract.StageType.FINANCE;
                        stage.DeliveryMethod = DeliveryMethod.UNITS_SHEDULE;
                        stage.PaymentMethod  = PaymentMethod.SCHEDULE;
//                        stage.DateEnd = stage.DateBegin;
//                        stage.DateFinish = stage.DateEnd;
                        stages.Add(stage);
                    }
                }
                if (record.StageCode.Substring(0, 3) != "Adv")
                {
                    if (String.IsNullOrEmpty(record.OrderCode))
                    {
                        throw new ArgumentException("Order Code is Empty", "OrderCode");
                    }
                    order = orders.FirstOrDefault(x => x.Code == record.OrderCode);
                    if (order == null)
                    {
                        order = os.FindObject <fmCOrder>(new BinaryOperator("Code", record.OrderCode, BinaryOperatorType.Equal));
                        if (order == null)
                        {
                            throw new ArgumentException("Order unknow", "OrderCode");
                        }
                        else
                        {
                            orders.Add(order);
                        }
                        stage.Order = order;
                    }
                    if (record.DateContract == null)
                    {
                        throw new ArgumentException("Date Contract is Empty", "DateContract");
                    }
                    delivery_unit = stage.DeliveryPlan.DeliveryUnits.FirstOrDefault(x => x.DatePlane == record.DateContract);
                    if (record.DateContract > stage.DateEnd)
                    {
                        stage.DateEnd = (DateTime)record.DateContract;
                    }
                    if (delivery_unit == null)
                    {
                        delivery_unit           = stage.DeliveryPlan.DeliveryUnitCreate();
                        delivery_unit.DatePlane = (DateTime)record.DateContract;
                    }
                    if (!delivery_units.Contains(delivery_unit))
                    {
                        delivery_units.Add(delivery_unit);
                    }
                    delivery_unit.Order = order;
                    if (record.Count == null)
                    {
                        throw new ArgumentException("Count is Empty", "Count");
                    }
                    if (record.Price == null)
                    {
                        throw new ArgumentException("Price is Empty", "Price");
                    }
                    if (String.IsNullOrEmpty(record.NomenclatureCode))
                    {
                        throw new ArgumentException("Nomenclature Code is Empty", "NomenclatureCode");
                    }
                    if (!record.NomenclatureCode.Contains("*I") && !record.NomenclatureCode.Contains("*E"))
                    {
                        csMaterial material = materials.FirstOrDefault(x => x.CodeTechnical == record.NomenclatureCode);
                        if (material == null)
                        {
                            throw new ArgumentException("Nomenclature unknow", "NomenclatureCode");
                        }
                        delivery_item = delivery_unit.DeliveryItems.FirstOrDefault(x => x.Nomenclature == material);
                        if (delivery_item == null)
                        {
                            delivery_item = delivery_unit.DeliveryItemsCreateMaterial();
                            ((crmDeliveryMaterial)delivery_item).Material = material;
                        }
                        delivery_item.CostCalculateMethod = CostCalculateMethod.CALC_COST;
                        delivery_item.NDSCalculateMethod  = NDSCalculateMethod.FROM_COST;
                        delivery_item.FullCalculateMethod = FullCalculateMethod.CALC_FULL;
                        delivery_item.Price     = (Decimal)record.Price;
                        delivery_item.CountUnit = delivery_item.Nomenclature.BaseUnit;
                        if (delivery_items.Contains(delivery_item))
                        {
                            delivery_item.CountValue += (Decimal)record.Count;
                        }
                        else
                        {
                            delivery_item.CountValue = (Decimal)record.Count;
                            delivery_items.Add(delivery_item);
                        }
                    }
                }
                if (record.DateContract == null)
                {
                    throw new ArgumentException("Date Contract is Empty", "DateContract");
                }
                payment_unit = stage.PaymentPlan.PaymentUnits.FirstOrDefault(x => x.DatePlane == record.DateContract && x is crmPaymentCasheLess);
                if (payment_unit == null)
                {
                    payment_unit           = stage.PaymentPlan.PaymentCasheLessCreate();
                    payment_unit.DatePlane = (DateTime)record.DateContract;
                    if (payment_unit.DatePlane > stage.DateFinish)
                    {
                        stage.DateFinish = payment_unit.DatePlane;
                    }
                }
                if (!payment_units.Contains(payment_unit))
                {
                    ((crmPaymentCasheLess)payment_unit).SummFull = (Decimal)record.SummaPayment;
                    payment_units.Add(payment_unit);
                }
                else
                {
                    ((crmPaymentCasheLess)payment_unit).SummFull += (Decimal)record.SummaPayment;
                }

                //                payment_item = payment_unit.PaymentItems.FirstOrDefault(x => x.Order == order);
                //                if (payment_item == null) {
                //                    payment_item = payment_unit.PaymentItemsCreateMoney();
                //                }
                //if (payment_unit.PaymentItems.Count == 0) {
                //    payment_item = payment_unit.PaymentItemsCreateMoney();
                //}
                //else {
                //    payment_item = payment_unit.PaymentItems[0];
                //}
                //if (payment_items.Contains(payment_item)) {
                //    payment_item.SummFull += (Decimal)record.SummaPayment;
                //    payment_item.AccountSumma += (Decimal)record.SummaPayment;
                //}
                //else {
                //    payment_item.SummFull = (Decimal)record.SummaPayment;
                //    payment_item.AccountSumma = (Decimal)record.SummaPayment;
                //    payment_items.Add(payment_item);
                //}
            }
            IList <crmDeliveryUnit> del_delivery_units = new List <crmDeliveryUnit>();
            IList <crmPaymentUnit>  del_payment_units  = new List <crmPaymentUnit>();

            foreach (crmStage stage in stages)
            {
                foreach (crmDeliveryUnit delivery_unit in stage.DeliveryPlan.DeliveryUnits)
                {
                    if (!delivery_units.Contains(delivery_unit))
                    {
                        del_delivery_units.Add(delivery_unit);
                    }
                }
                foreach (crmPaymentUnit payment_unit in stage.PaymentPlan.PaymentUnits)
                {
                    if (!payment_units.Contains(payment_unit))
                    {
                        del_payment_units.Add(payment_unit);
                    }
                }
            }
            os.Delete(del_delivery_units);
            os.Delete(del_payment_units);
        }
Пример #7
0
 public void OrdersRemove(fmCOrder order)
 {
 }
Пример #8
0
        public void Import(IObjectSpace os, String file_name)
        {
            FileHelperEngine <DealDataImport> engine = new FileHelperEngine <DealDataImport>();

            engine.Options.IgnoreFirstLines = 1;
            engine.Options.IgnoreEmptyLines = true;
            Int32 line = 0;

            //            DealDataImport[] deal_data = engine.ReadStream(reader);
            DealDataImport[]        deal_data      = engine.ReadFile(file_name);
            IList <fmCOrder>        orders         = new List <fmCOrder>();
            IList <crmStage>        stages         = new List <crmStage>();
            IList <crmDeliveryUnit> delivery_units = new List <crmDeliveryUnit>();
            IList <crmDeliveryItem> delivery_items = new List <crmDeliveryItem>();
            IList <crmPaymentUnit>  payment_units  = new List <crmPaymentUnit>();
            IList <crmPaymentItem>  payment_items  = new List <crmPaymentItem>();
            IList <csNomenclature>  materials      = os.GetObjects <csNomenclature>();

            foreach (DealDataImport record in deal_data)
            {
                fmCOrder        order         = null;
                crmStage        stage         = null;
                crmDeliveryUnit delivery_unit = null;
                crmDeliveryItem delivery_item = null;
                crmPaymentUnit  payment_unit  = null;
                line++;
                //                crmPaymentItem payment_item = null;
                if (!String.IsNullOrEmpty(record.OrderCode))
                {
                    order = orders.FirstOrDefault(x => x.Code == record.OrderCode);
                    if (order == null)
                    {
                        order = os.FindObject <fmCOrder>(new BinaryOperator("Code", record.OrderCode, BinaryOperatorType.Equal));
                        if (order == null)
                        {
                            throw new ArgumentException("Неизвестный заказ: " + record.OrderCode + " Строка: " + line, "OrderCode");
                        }
                        else
                        {
                            orders.Add(order);
                        }
                    }
                }
                if (String.IsNullOrEmpty(record.StageCode))
                {
                    throw new ArgumentException("Номер этапа пустой. Строка: " + line, "StageCode");
                }
                if (record.StageCode.Substring(0, 3) == "Adv")
                {
                    stage = StageStructure.FirstStage;
                }
                else
                {
                    stage = StageStructure.Stages.FirstOrDefault(x => x.Code == record.StageCode);
                    if (stage == null)
                    {
                        stage      = StageStructure.FirstStage.SubStagesCreate();
                        stage.Code = record.StageCode;
                    }
                    if (!stages.Contains(stage))
                    {
                        stage.Order          = order;
                        stage.StageType      = Contract.StageType.FINANCE;
                        stage.DeliveryMethod = DeliveryMethod.UNITS_SHEDULE;
                        stage.PaymentMethod  = PaymentMethod.SCHEDULE;
                        //                        stage.DateEnd = stage.DateBegin;
                        //                        stage.DateFinish = stage.DateEnd;
                        stages.Add(stage);
                    }
                }
                if (record.StageCode.Substring(0, 3) != "Adv")
                {
                    if (order == null)
                    {
                        throw new ArgumentException("Заказ не найден", "OrderCode");
                    }
                    if (record.DateContract == null)
                    {
                        throw new ArgumentException("Незаполнена плановая дата исполнения. Строка: " + line, "DateContract");
                    }
                    delivery_unit = stage.DeliveryPlan.DeliveryUnits.FirstOrDefault(x => x.DatePlane == record.DateContract);
                    if (record.DateContract > stage.DateEnd)
                    {
                        stage.DateEnd = (DateTime)record.DateContract;
                    }
                    if (delivery_unit == null)
                    {
                        delivery_unit           = stage.DeliveryPlan.DeliveryUnitCreate();
                        delivery_unit.DatePlane = (DateTime)record.DateContract;
                    }
                    if (!delivery_units.Contains(delivery_unit))
                    {
                        delivery_units.Add(delivery_unit);
                    }
                    delivery_unit.Order = order;
                    if (record.Count == null)
                    {
                        throw new ArgumentException("Кол-во пустое. Строка: " + line, "Count");
                    }
                    if (record.Price == null)
                    {
                        throw new ArgumentException("Цена пустая. Строка: " + line, "Price");
                    }
                    if (String.IsNullOrEmpty(record.NomenclatureCode))
                    {
                        throw new ArgumentException("Номенклатура пустая. Строка: " + line, "NomenclatureCode");
                    }
                    if (!record.NomenclatureCode.Contains("*I") && !record.NomenclatureCode.Contains("*E"))
                    {
//                        csMaterial material = ;
                        csNomenclature nomenclature = materials.FirstOrDefault(x => x.CodeTechnical == record.NomenclatureCode);
                        if (nomenclature == null)
                        {
                            throw new ArgumentException("Номенклатура: " + record.NomenclatureCode + " ненайдена. Строка: " + line, "NomenclatureCode");
                        }
                        delivery_item = delivery_unit.DeliveryItems.FirstOrDefault(x => x.Nomenclature == nomenclature);
                        if (delivery_item == null)
                        {
                            if (nomenclature is csMaterial)
                            {
                                delivery_item = delivery_unit.DeliveryItemsCreateMaterial();
                                ((crmDeliveryMaterial)delivery_item).Material = nomenclature as csMaterial;
                            }
                            else if (nomenclature is csService)
                            {
                                delivery_item = delivery_unit.DeliveryItemsCreateService();
                                ((crmDeliveryService)delivery_item).Service = nomenclature as csService;
                            }
                            else
                            {
                                throw new ArgumentException("Номенклатура: " + record.NomenclatureCode + " неверного типа. Строка: " + line, "NomenclatureCode");
                            }
                        }
                        delivery_item.CostCalculateMethod = CostCalculateMethod.CALC_COST;
                        delivery_item.NDSCalculateMethod  = NDSCalculateMethod.FROM_COST;
                        delivery_item.FullCalculateMethod = FullCalculateMethod.CALC_FULL;
                        delivery_item.Price     = (Decimal)record.Price;
                        delivery_item.CountUnit = delivery_item.Nomenclature.BaseUnit;
                        if (delivery_items.Contains(delivery_item))
                        {
                            delivery_item.CountValue += (Decimal)record.Count;
                        }
                        else
                        {
                            delivery_item.CountValue = (Decimal)record.Count;
                            delivery_items.Add(delivery_item);
                        }
                    }
                }
                if (record.DateContract == null)
                {
                    throw new ArgumentException("Дата плановая исполнения не заполнена. Строка: " + line, "DateContract");
                }
                payment_unit = stage.PaymentPlan.PaymentUnits.FirstOrDefault(x => x.DatePlane == record.DateContract && x is crmPaymentCasheLess);
                //if (payment_unit != null && !payment_units.Contains(payment_unit)) {
                //    os.Delete(payment_unit);
                //    payment_unit = null;
                //}
                if (payment_unit == null)
                {
                    payment_unit           = stage.PaymentPlan.PaymentCasheLessCreate();
                    payment_unit.DatePlane = (DateTime)record.DateContract;
                    if (payment_unit.DatePlane > stage.DateFinish)
                    {
                        stage.DateFinish = payment_unit.DatePlane;
                    }
                }
                payment_unit.Order = order;
                if (!payment_units.Contains(payment_unit))
                {
                    ((crmPaymentCasheLess)payment_unit).SummFull = (Decimal)record.SummaPayment;
                    payment_units.Add(payment_unit);
                }
                else
                {
                    ((crmPaymentCasheLess)payment_unit).SummFull += (Decimal)record.SummaPayment;
                }

                //                payment_item = payment_unit.PaymentItems.FirstOrDefault(x => x.Order == order);
                //                if (payment_item == null) {
                //                    payment_item = payment_unit.PaymentItemsCreateMoney();
                //                }
                //if (payment_unit.PaymentItems.Count == 0) {
                //    payment_item = payment_unit.PaymentItemsCreateMoney();
                //}
                //else {
                //    payment_item = payment_unit.PaymentItems[0];
                //}
                //if (payment_items.Contains(payment_item)) {
                //    payment_item.SummFull += (Decimal)record.SummaPayment;
                //    payment_item.AccountSumma += (Decimal)record.SummaPayment;
                //}
                //else {
                //    payment_item.SummFull = (Decimal)record.SummaPayment;
                //    payment_item.AccountSumma = (Decimal)record.SummaPayment;
                //    payment_items.Add(payment_item);
                //}
            }
            IList <crmDeliveryUnit> del_delivery_units = new List <crmDeliveryUnit>();
            IList <crmDeliveryItem> del_delivery_items = new List <crmDeliveryItem>();
            IList <crmPaymentUnit>  del_payment_units  = new List <crmPaymentUnit>();
            IList <crmPaymentItem>  del_payment_items  = new List <crmPaymentItem>();

            foreach (crmStage stage in stages)
            {
                foreach (crmDeliveryUnit delivery_unit in stage.DeliveryPlan.DeliveryUnits)
                {
                    if (!delivery_units.Contains(delivery_unit))
                    {
                        del_delivery_units.Add(delivery_unit);
                        foreach (crmDeliveryItem item in delivery_unit.DeliveryItems)
                        {
                            del_delivery_items.Add(item);
                        }
                    }
                    else
                    {
                        foreach (crmDeliveryItem item in delivery_unit.DeliveryItems)
                        {
                            if (!delivery_items.Contains(item))
                            {
                                del_delivery_items.Add(item);
                            }
                        }
                    }
                }
                foreach (crmPaymentUnit payment_unit in stage.PaymentPlan.PaymentUnits)
                {
                    if (!payment_units.Contains(payment_unit))
                    {
                        del_payment_units.Add(payment_unit);
                        foreach (crmPaymentItem item in payment_unit.PaymentItems)
                        {
                            del_payment_items.Add(item);
                        }
                    }
                    else
                    {
                        foreach (crmPaymentItem item in payment_unit.PaymentItems)
                        {
                            if (!payment_items.Contains(item))
                            {
                                del_payment_items.Add(item);
                            }
                        }
                    }
                }
            }
            // Не удаляем PaymentItems, поскольку не создаем их, а создаем PaymentUnitCashLess, который сам создает Item
            //            os.Delete(del_payment_items);
            os.Delete(del_payment_units);
            os.Delete(del_delivery_items);
            os.Delete(del_delivery_units);
        }
Пример #9
0
        public static TrwRefCashFlow AutoDetect(IObjectSpace os, Boolean CashDirect, fmCOrder order, fmPRPayType pay_type, fmCostItem cost_item)
        {
            IList <TrwRefCashFlow> all_refs = os.GetObjects <TrwRefCashFlow>();
            TrwRefCashFlow         current  = null;

            if (CashDirect)
            {
                return(null);
            }
            else
            {
                if (cost_item.Code == "2000" ||
                    cost_item.Code == "2001")
                {
                    return(GetRefByFullCode(os, all_refs, null, "2.1.1.2.1"));
                }
                if (cost_item.Code == "2003" ||
                    cost_item.Code == "2006")
                {
                    return(GetRefByFullCode(os, all_refs, null, "2.1.1.2.2"));
                }
                if (cost_item.Code == "2002" ||
                    cost_item.Code == "2004" ||
                    cost_item.Code == "2005")
                {
                    return(GetRefByFullCode(os, all_refs, null, "2.1.1.2.3"));
                }
                if (order.Subject != null && order.Subject.Direction != null && order.AnalitycFinanceSource != null && order.AnalitycFinanceSource.Code == "Коммерческий" &&
                    (order.Subject.Direction.Code != "ПТР" || order.Subject.Direction.Code != "НР" || order.Subject.Direction.Code != "СП"))
                {
                    current = GetRefByFullCode(os, all_refs, null, "2.1.1.1");
                    if (cost_item.Code == "6003")
                    {
                        if (order.AnalitycRegion.IsVED)
                        {
                            if (pay_type == fmPRPayType.PREPAYMENT)
                            {
                                return(GetRefByFullCode(os, all_refs, current, "1.1.1"));
                            }
                            if (pay_type == fmPRPayType.POSTPAYMENT)
                            {
                                return(GetRefByFullCode(os, all_refs, current, "1.1.2"));
                            }
                        }
                        else if (order.AnalitycOrderSource.IsGZ)
                        {
                            if (pay_type == fmPRPayType.PREPAYMENT)
                            {
                                return(GetRefByFullCode(os, all_refs, current, "1.2.1"));
                            }
                            if (pay_type == fmPRPayType.POSTPAYMENT)
                            {
                                return(GetRefByFullCode(os, all_refs, current, "1.2.2"));
                            }
                        }
                        else
                        {
                            if (pay_type == fmPRPayType.PREPAYMENT)
                            {
                                return(GetRefByFullCode(os, all_refs, current, "1.3.1"));
                            }
                            if (pay_type == fmPRPayType.POSTPAYMENT)
                            {
                                return(GetRefByFullCode(os, all_refs, current, "1.3.2"));
                            }
                        }
                    }
                    else if (cost_item.Code == "6000" || cost_item.Code == "6001" || cost_item.Code == "6002" ||
                             cost_item.Code == "6004" || cost_item.Code == "6005" || cost_item.Code == "6006" || cost_item.Code == "6007")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "3"));
                    }
                    else if (cost_item.Code == "7001")
                    {
                        if (pay_type == fmPRPayType.PREPAYMENT)
                        {
                            return(GetRefByFullCode(os, all_refs, current, "2.1.1"));
                        }
                        if (pay_type == fmPRPayType.POSTPAYMENT)
                        {
                            return(GetRefByFullCode(os, all_refs, current, "2.2.1"));
                        }
                    }
                    else
                    {
                        if (pay_type == fmPRPayType.PREPAYMENT)
                        {
                            return(GetRefByFullCode(os, all_refs, current, "2.1.2"));
                        }
                        if (pay_type == fmPRPayType.POSTPAYMENT)
                        {
                            return(GetRefByFullCode(os, all_refs, current, "2.2.2"));
                        }
                    }
                }
                else if (order.Subject != null && order.Subject.Direction != null && order.Subject.Direction.Code == "ПТР")
                {
                    current = GetRefByFullCode(os, all_refs, null, "2.1.3");
                }
                else if (order.Subject != null && order.Subject.Direction != null && order.Subject.Direction.Code == "НР")
                {
                    current = GetRefByFullCode(os, all_refs, null, "2.1.1.3");
                    String smeta = "";
                    if (order.Code.Length == 8)
                    {
                        smeta = order.Code.Substring(6, 2);
                    }
                    if (smeta == "10" || smeta == "11" || smeta == "12" || smeta == "22" || smeta == "09" && order.Code != "26015509")
                    {
                        if (cost_item.Code == "6000" || cost_item.Code == "6001" || cost_item.Code == "6002" ||
                            cost_item.Code == "6004" || cost_item.Code == "6005" || cost_item.Code == "6006" ||
                            cost_item.Code == "6007" || cost_item.Code == "6003")
                        {
                            return(GetRefByFullCode(os, all_refs, current, "1.1"));
                        }
                        else
                        {
                            return(GetRefByFullCode(os, all_refs, current, "1.2"));
                        }
                    }
                    else if (order.Code == "26020500")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "13"));
                    }
                    else if ((order.Code == "26003100" || order.Code == "26503100") &&
                             (cost_item.Code == "7007"))
                    {
                        return(GetRefByFullCode(os, all_refs, current, "15"));
                    }
                    else if (order.Code == "26020000" && cost_item.Code == "7012" ||
                             order.Code == "26520300" && cost_item.Code == "7012")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "6"));
                    }
                    else if ((order.Code == "26020000" || order.Code == "26002000" || order.Code == "26502100" || order.Code == "26520300") &&
                             (cost_item.Code == "2101" || cost_item.Code == "2102" || order.Code == "2103"))
                    {
                        return(GetRefByFullCode(os, all_refs, current, "7"));
                    }
                    else if (order.Code == "23210000" || order.Code == "23220000")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "4"));
                    }
                    else if (order.Code == "23230000")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "5"));
                    }
                    else if (order.Code == "26003116")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "8"));
                    }
                    else if (order.Code == "26015407" || order.Code == "25006407")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "9"));
                    }
                    else if (order.Code == "26020400")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "17"));
                    }
                    else if (smeta == "37" || smeta == "34" ||
                             order.Code == "26017400" || order.Code == "26017300")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "16"));
                    }
                    else if (smeta == "39" ||
                             order.Code == "26015107" || order.Code == "26015307" || order.Code == "26020607" ||
                             order.Code == "25006107" || order.Code == "25006307")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "12"));
                    }
                    else if (smeta == "13" || smeta == "14" || smeta == "15" || smeta == "16" && order.Code != "26003116" ||
                             smeta == "17" || smeta == "18" || smeta == "21" || smeta == "26" || smeta == "40" ||
                             order.Code == "26015509")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "2"));
                    }
                    else if (smeta == "19" || smeta == "20" || order.Code == "26004000" || order.Code == "26012500")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "3"));
                    }
                    else if (smeta == "31" || smeta == "33")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "10"));
                    }
                    else if (smeta == "27")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "11"));
                    }
                    else if (smeta == "35")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "18"));
                    }
                    else if (smeta == "29" || smeta == "30")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "19"));
                    }
                    else if (smeta == "23" || smeta == "24")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "21"));
                    }
                    else if (smeta == "25" || smeta == "02" || smeta == "03" || smeta == "04" || smeta == "05" ||
                             smeta == "06" || smeta == "36" || smeta == "28" || smeta == "41" ||
                             order.Code == "26016000" || order.Code == "26014600" || order.Code == "23210008" ||
                             order.Code == "23220008" || order.Code == "26020000" || order.Code == "26520300" ||
                             order.Code == "25008300")
                    {
                        return(GetRefByFullCode(os, all_refs, current, "23"));
                    }
                }
                else if (order.Subject != null && order.Subject.Direction != null && order.Subject.Direction.Code == "СП")
                {
                    current = GetRefByFullCode(os, all_refs, null, "2.1.1.7");
                }
            }
            return(null);
        }