Exemplo n.º 1
0
        /// <summary>
        /// Allocate the next unused cheque number/deposit number/etc.
        /// </summary>
        protected void allocateDocumentIdentifier(Extended_Document document, FullAccount acct)
        {
            if ((document.idDocument == null || document.idDocument == 0) && document.DocumentIdentifier == "<next>")
            {
                DocType type      = (DocType)document.DocumentTypeId;
                int     nextDocId = 0;
                switch (type)
                {
                case DocType.Invoice:
                case DocType.Payment:
                case DocType.CreditMemo:
                case DocType.Bill:
                case DocType.BillPayment:
                case DocType.Credit:
                case DocType.GeneralJournal:
                    nextDocId = Settings.NextNumber(type);
                    break;

                case DocType.Withdrawal:
                case DocType.Deposit:
                case DocType.CreditCardCharge:
                case DocType.CreditCardCredit:
                    nextDocId = acct.NextNumber(type);
                    break;
                }
                document.DocumentIdentifier = nextDocId != 0 ? nextDocId.ToString() : "";
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieve document, or prepare new one
        /// </summary>
        public JObject document(int id, DocType type)
        {
            Title = Title.Replace("Document", type.UnCamel());
            Extended_Document header = getDocument <Extended_Document>(id);

            if (header.idDocument == null)
            {
                header.DocumentTypeId     = (int)type;
                header.DocType            = type.UnCamel();
                header.DocumentDate       = Utils.Today;
                header.DocumentName       = "";
                header.DocumentIdentifier = Settings.NextNumber(type).ToString();
                if (GetParameters["name"].IsInteger())
                {
                    JObject name = Database.QueryOne("*", "WHERE Type = " + Database.Quote(NameType) + " AND idNameAddress = " + GetParameters["name"], "NameAddress");
                    if (name != null)
                    {
                        checkNameType(name.AsString("Type"), NameType);
                        header.DocumentNameAddressId = name.AsInt("idNameAddress");
                        header.DocumentAddress       = name.AsString("Address");
                        header.DocumentName          = name.AsString("Name");
                    }
                }
            }
            else
            {
                checkDocType(header.DocumentTypeId, type);
                checkNameType(header.DocumentNameAddressId, NameType);
            }
            JObject record = new JObject().AddRange("header", header);

            nextPreviousDocument(record, "WHERE DocumentTypeId = " + (int)type);
            record.AddRange("VatCodes", SelectVatCodes(),
                            "Names", SelectNames(NameType));
            return(record);
        }