public void Product(int id) { Select sel = new Select(); JObject inUse = Database.QueryOne("SELECT idLine FROM Line WHERE ProductId = " + id); Record = new JObject().AddRange("header", Database.Get<FullProduct>(id), "canDelete", inUse == null || inUse.IsAllNull(), "VatCodes", sel.VatCode(""), "Accounts", sel.IncomeAccount("")); }
/// <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); Database.NextPreviousDocument(record, "WHERE DocumentTypeId = " + (int)type); Select s = new Select(); record.AddRange("VatCodes", s.VatCode(""), "Names", s.Name(NameType, "")); return record; }
/// <summary> /// Get a document for editing /// </summary> public void Document(int id, DocType type) { Title = Title.Replace("Document", type.UnCamel()); JObject record = GetDocument(id, type); dynamic header = ((dynamic)record).header; Database.NextPreviousDocument(record, "JOIN Journal ON DocumentId = idDocument WHERE DocumentTypeId = " + (int)type + (header.DocumentAccountId > 0 ? " AND AccountId = " + header.DocumentAccountId : "")); Select s = new Select(); record.AddRange("Accounts", s.Account(""), "VatCodes", s.VatCode(""), "Names", s.Other("")); Record = record; }