/// <summary> /// Approve or reject record /// </summary> /// <param name="document"></param> /// <returns></returns> public async Task <JsonResult> ApproveOrRejectRecord(DocumentModel document) { // Get user call api UserContext context = UserConnect.GetContext(HttpContext); UserMobile user = UserConnect.GetUserConnected(context.Token, context.Ip, context.UserAgent); try { var approvalsMgmt = GetApprove(user); var recordId = "Purchase Header: 1," + document.IdDoc; if (document.IsApprove) { approvalsMgmt.ApproveRecordApprovalRequest(recordId); } else { approvalsMgmt.RejectRecordApprovalRequest(recordId); } return(new JsonResult { Data = true, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception ex) { return(new JsonResult { Data = false, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); throw ex; } }
/// <summary> /// Get value to check /// </summary> /// <param name="document"></param> /// <returns></returns> public async Task <JsonResult> GetValueToCheck(DocumentModel document) { // Get user call api UserContext context = UserConnect.GetContext(HttpContext); UserMobile user = UserConnect.GetUserConnected(context.Token, context.Ip, context.UserAgent); LinesPurchasOrders_PortClient linesPurchasOrders_PortClient = GetLines(user); List <DocumentValuesModel> documentValues = new List <DocumentValuesModel>(); try { var lines = linesPurchasOrders_PortClient.ReadMultiple(null, null, 0).Where(art => art.Document_No == document.IdDoc.ToString()); documentValues.Add(new DocumentValuesModel { Name = "Total_Amount_Excl_VAT", Value = lines.FirstOrDefault().Total_Amount_Excl_VAT.ToString() }); documentValues.Add(new DocumentValuesModel { Name = "Total_Amount_Incl_VAT", Value = lines.FirstOrDefault().Total_Amount_Incl_VAT.ToString() }); } catch (Exception ex) { throw ex; } return(new JsonResult { Data = documentValues, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public async Task <ActionResult> GetDocuments() { // Get user call api UserContext context = UserConnect.GetContext(HttpContext); UserMobile user = UserConnect.GetUserConnected(context.Token, context.Ip, context.UserAgent); List <DocumentModel> listsDocuments = new List <DocumentModel>(); try { var purchaseOrders_PortClient = GetSalesOrder(user); // filter on statut PurchaseOrders_Filter fi = new PurchaseOrders_Filter(); fi.Field = PurchaseOrders_Fields.Status; fi.Criteria = "Pending Approval"; PurchaseOrders_Filter[] fiArray = new PurchaseOrders_Filter[] { fi }; var results = await purchaseOrders_PortClient.ReadMultipleAsync(fiArray, null, 0); var approvalsMgmt = GetApprove(user); var recordlink = GetRecordLink(user); RecordLinkPage_Filter rlp = new RecordLinkPage_Filter(); RecordLinkPage_Filter[] rlparray = new RecordLinkPage_Filter[] { rlp }; foreach (var sale in results.ReadMultiple_Result1) { var recordId = "Purchase Header: 1," + sale.No; // check if user connected can approve a doc if (approvalsMgmt.HasOpenApprovalEntriesForCurrentUser(recordId)) { var docs = recordlink.ReadMultiple(rlparray, null, 0).Where(d => d.Record_ID == recordId); listsDocuments.AddRange(docs.Select(d => new DocumentModel() { IdDoc = sale.No, VendorName = sale.Buy_from_Vendor_Name, VendorInvoiceNo = sale.Vendor_Invoice_No, VendorShipNo = sale.Vendor_Shipment_No, DocumentDate = sale.Document_Date.ToString(), DocName = d.Description, Url = d.URL1, DocDate = d.Created, DocSatut = ((EnumStatut.Values)d.Statut).GetBool() }).ToList()); } } } catch (Exception ex) { throw ex; } return(new JsonResult { Data = listsDocuments, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }