Exemple #1
0
        static public void ImportAvansData(IObjectSpace os, String file_name)
        {
            fmCAVTInvoiceType inv_type = os.GetObjects <fmCAVTInvoiceType>().FirstOrDefault(x => x.Prefix == "ю");
            FileHelperEngine <fmCAVTInvoiceAvansImport> engine = new FileHelperEngine <fmCAVTInvoiceAvansImport>();

            engine.Options.IgnoreFirstLines = 1;
            fmCAVTInvoiceAvansImport[] avans = engine.ReadFile(file_name);
            foreach (fmCAVTInvoiceAvansImport avan in avans)
            {
                avan.VO_CODE   = avan.VO_CODE.Trim();
                avan.SF_NUMBER = avan.SF_NUMBER.Trim();
                avan.PP_NUMBER = avan.PP_NUMBER.Trim();
                avan.TEXT      = avan.TEXT.Trim();
                fmCAVTInvoiceBase invoice = os.FindObject <fmCAVTInvoiceBase>(
                    XPQuery <fmCAVTInvoiceBase> .TransformExpression(
                        ((ObjectSpace)os).Session,
                        rec => rec.Customer.Code == avan.VO_CODE &&
                        rec.Number == avan.SF_NUMBER &&
                        rec.Date >= avan.SF_DATE.Date &&
                        rec.Date <= avan.SF_DATE.Date.AddDays(1)
                        ));
                fmCAVTInvoiceLine line = null;
                if (invoice == null)
                {
                    invoice          = os.CreateObject <fmCAVTInvoiceBase>();
                    invoice.Number   = avan.SF_NUMBER;
                    invoice.Date     = avan.SF_DATE.Date;
                    invoice.Customer = os.GetObjects <crmCParty>(new BinaryOperator("Code", avan.VO_CODE)).FirstOrDefault();
                    invoice.Supplier = os.GetObjects <crmCParty>(new BinaryOperator("Code", "2518")).FirstOrDefault();
                }
                if (invoice != null)
                {
                    invoice.InvoiceType = inv_type;
                    if (invoice.Lines.Count > 0)
                    {
                        line = invoice.Lines[0];
                    }
                    if (line == null)
                    {
                        line = os.CreateObject <fmCAVTInvoiceLine>();
                        invoice.Lines.Add(line);
                    }
                    line.NomenclatureText = avan.TEXT;
                    line.AVTSumm          = avan.SUMM_VAT;
                    line.Cost             = avan.SUMM_ALL - avan.SUMM_VAT;
                    //                    fmCAVTInvoiceVersion.Payment pay = new fmCAVTInvoiceVersion.Payment() {
                    fmCAVTInvoiceVersion.fmCAVTInvoicePayment pay = null;
                    if (invoice.PaymentsList.Count > 0)
                    {
                        pay = invoice.PaymentsList[0];
                    }
                    if (pay == null)
                    {
                        pay = os.CreateObject <fmCAVTInvoiceVersion.fmCAVTInvoicePayment>();
                        invoice.PaymentsList.Add(pay);
                    }
                    pay.Number = avan.PP_NUMBER;
                    pay.Date   = avan.PP_DATE;
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ses"></param>
        /// <param name="inv_type"></param>
        /// <param name="inv_date"></param>
        /// <returns></returns>
        public static Int32 GenerateNumber(Session ses, Guid object_oid, fmCAVTInvoiceType inv_type, DateTime inv_date, Int32 number)
        {
            String           per  = inv_date.ToString("yyyyMM");
            CriteriaOperator oper = CriteriaOperator.And(new BinaryOperator("InvoiceType", inv_type.Oid, BinaryOperatorType.Equal),
                                                         new BinaryOperator("Period", per, BinaryOperatorType.Equal),
                                                         new BinaryOperator("Number", -1, BinaryOperatorType.Equal));

#pragma warning disable 0162
            for (int probe = 0; probe < 5; probe++)
            {
#pragma warning restore 0162
                using (UnitOfWork uow = new UnitOfWork(ses.DataLayer)) {
                    fmCAVTInvoiceNumberGenerator ng = uow.FindObject <fmCAVTInvoiceNumberGenerator>(
                        PersistentCriteriaEvaluationBehavior.BeforeTransaction, oper);
                    if (ng == null)
                    {
                        ng = new fmCAVTInvoiceNumberGenerator(uow)
                        {
                            Period      = per,
                            InvoiceType = inv_type.Oid,
                            Number      = -1
                        };
                    }
                    fmCAVTInvoiceNumberGenerator num = null;
                    if (object_oid != Guid.Empty)
                    {
                        num = uow.FindObject <fmCAVTInvoiceNumberGenerator>(
                            PersistentCriteriaEvaluationBehavior.BeforeTransaction,
                            new BinaryOperator("SourceObject", object_oid));
                    }
                    if (num == null)
                    {
                        //
                        if (number != 0)
                        {
                            if (number > ng.NextNumber)
                            {
                                ng.NextNumber = number;
                            }
                        }
                        else
                        {
                            number = ++ng.NextNumber;
                        }
                        num = new fmCAVTInvoiceNumberGenerator(uow)
                        {
                            SourceObject = object_oid,
                            Period       = per,
                            InvoiceType  = inv_type.Oid,
                            Number       = number
                        };
                    }
                    else
                    {
                        if (number != 0 && number != num.Number)
                        {
                            throw new LockConflictException();
                        }
                        else
                        {
                            number = num.Number;
                        }
                    }
                    //
                    uow.CommitChanges();
                    //
                    //return ng.NextNumber;
                    //                    return inv_type.Prefix + per + ng.NextNumber.ToString("00000");
                    return(number);
                }
            }
            throw new LockConflictException();
        }