Пример #1
0
        public InvoiceAutoNumberConfig GetInvoiceAutoNumberConfig(string companyId)
        {
            MongoCollection <InvoiceAutoNumberConfig> collection = mongo.MongoDatabase.GetCollection <InvoiceAutoNumberConfig>(typeof(InvoiceAutoNumberConfig).Name);
            InvoiceAutoNumberConfig cfg = collection.FindOneAs <InvoiceAutoNumberConfig>(Query.And(
                                                                                             Query.EQ("_id", typeof(InvoiceAutoNumberConfig).Name),
                                                                                             Query.EQ(COMPANY_ID_FIELD, BsonValue.Create(companyId))));

            if (cfg == null)
            {
                cfg = new InvoiceAutoNumberConfig(typeof(InvoiceAutoNumberConfig).Name, AutoNumberMode.Default, DEFAULT_PREFIX, companyId);
                collection.Save <InvoiceAutoNumberConfig>(cfg);
            }

            return(cfg);
        }
Пример #2
0
        public InvoiceAutoNumberConfig GetInvoiceAutoNumberConfig(string companyId)
        {
            MongoCollection<InvoiceAutoNumberConfig> collection =  mongo.MongoDatabase.GetCollection<InvoiceAutoNumberConfig>(typeof(InvoiceAutoNumberConfig).Name);
            InvoiceAutoNumberConfig cfg = collection.FindOneAs<InvoiceAutoNumberConfig>(Query.And(
                Query.EQ("_id", typeof(InvoiceAutoNumberConfig).Name),
                Query.EQ(COMPANY_ID_FIELD, BsonValue.Create(companyId))));

            if (cfg == null)
            {
                cfg = new InvoiceAutoNumberConfig(typeof(InvoiceAutoNumberConfig).Name, AutoNumberMode.Default, DEFAULT_PREFIX, companyId);
                collection.Save<InvoiceAutoNumberConfig>(cfg);
            }

            return cfg;
        }
Пример #3
0
        public string GenerateInvoiceNumber(DateTime transactionDate, string companyId)
        {
            this.transactionDate = transactionDate;
            this.companyId       = companyId;
            InvoiceAutoNumberConfig cfg = GetInvoiceAutoNumberConfig(companyId);

            switch (cfg.Mode)
            {
            case AutoNumberMode.Yearly:
                return(mongo.Save(GetInvoiceAutoNumberYearly().Next()).InvoiceNumberInStringFormat(cfg.Prefix));

            case AutoNumberMode.Monthly:
                return(mongo.Save(GetInvoiceAutoNumberMonthly().Next()).InvoiceNumberInStringFormat(cfg.Prefix));

            default:
                return(mongo.Save(GetInvoiceAutoNumberDefault().Next()).InvoiceNumberInStringFormat(cfg.Prefix));
            }
        }