public void createInvoice(Record document) { if (SafeUser != null && SafeUser.isLoggedIn()) { try { SqlHelper helper = new SqlHelper(); SecurityDAL sdal = new SecurityDAL(helper); if (sdal.hasPermission(SafeUser.SignIN.UID, "UPDATE") && sdal.hasPermission(SafeUser.SignIN.UID, "DELETE")) { ProductInventoryDAL piDAL = new ProductInventoryDAL(helper); ProductDocumentDAL pdDAL = new ProductDocumentDAL(helper); ProductTypeDAL ptDAL = new ProductTypeDAL(helper); InventoryDocumentationDAL idDAL = new InventoryDocumentationDAL(helper); ProductType type = ptDAL.getProductType(document.ProductType); if (type == null) { ptDAL.addProductType(document.ProductType); type = ptDAL.getProductType(document.ProductType); } ProductInventory product = piDAL.getProduct(document.ProductName, type.TID); if (product != null && product.TotalQuantity - document.ProductQuantity >= 0) { product.TotalQuantity += document.ProductQuantity; piDAL.updateProduct(product); } else { log(404, "No such product"); return; } ProductDocument delivery = new ProductDocument(); delivery.Name = document.DocumentName; delivery.PrID = product.PrID; delivery.Description = document.Description; delivery.Quantity = document.ProductQuantity; pdDAL.addDocument(delivery); delivery = pdDAL.getDocument(document.DocumentName, product.PrID, document.ProductQuantity, document.Description); idDAL.assignDocument(SafeUser.SignIN.UID, delivery.DocumentID); } }catch (Exception ex) { log(ex); } } }