// //Example routine to add an invoice into the fsInvPost Object // without images bool ProcessInvoiceNoImage(fsInvPost _invPost, int _transKey, object _debtorKey, object _invNumber, object _invAmount, object _invDate, object _invDescr, string _enteredUserId) { bool _successful = false; try { //Request API to start a new invoice if (!_invPost.StartInvoice()) { throw new Exception("Unsuccessfully started new invoice. " + _invPost.OutErrorMsg); } //Request to clear prior user id information _invPost.ClearUserId(); //Assign the CADENCE DebtorKey to the new invoice string _label = "DebtorKey"; if (!_invPost.PutFld(ref _label, ref _debtorKey)) { throw new Exception("Unsuccessfully stored debtorkey." + _invPost.OutErrorMsg); } //Assign the CADENCE invoice amount to the new invoice _label = "InvAmt"; if (!_invPost.PutFld(ref _label, ref _invAmount)) { throw new Exception("Unsuccessfully stored invoice amount. " + _invPost.OutErrorMsg); } //Assign the CADENCE invoice # to the new invoice _label = "InvNo"; if (!_invPost.PutFld(ref _label, ref _invNumber)) { throw new Exception("Unsuccessfully stored invoice #. " + _invPost.OutErrorMsg); } //Assign the CADENCE invoice date to the new invoice _label = "InvDate"; if (!_invPost.PutFld(ref _label, ref _invDate)) { throw new Exception("Unsuccessfully stored invoice date. " + _invPost.OutErrorMsg); } //Assign the CADENCE invoice description to the new invoice _label = "InvDescr"; if (!_invPost.PutFld(ref _label, ref _invDescr)) { throw new Exception("Unsuccessfully stored invoice description. " + _invPost.OutErrorMsg); } //Assign the CADENCE invoice user id _invPost.SetUserId(ref _enteredUserId); if (!_invPost.WrapInvoice()) { throw new Exception("Unsuccessfully wrapped the invoice into database. " + _invPost.OutErrorMsg); } //set indicator of success _successful = true; } catch (Exception ex) { throw ex; } return _successful; }
//Example - Routine to process a batch of invoices using fsInvPost public bool ProcessBatchOfInvoices(int _transKey, int _BatchNo) { bool _successful = false; bool _OkToProcessInvoice = false; string _dbType = "SQL"; string _dbName = "Cadence_Test_308"; string _dbServer = "Tasql1"; string _dbLogin = "******"; string _dbPassword = "******"; decimal _debitInvAmt = 0; decimal _creditInvAmt = 0; decimal _serviceFeeAmt = 0; decimal _escrowAmt = 0; decimal _expenseAmt = 0; decimal _recourseAmt = 0; decimal _netAmtToAdv = 0; int _debtorKey = 694; string _invNumber = Convert.ToString("11111"); decimal _invAmount = Convert.ToDecimal(100); DateTime _invDate = Convert.ToDateTime("1/1/2014"); string _invDescr = Convert.ToString("test invoice"); string _enteredUserId = Convert.ToString("~~mobile"); fsInvPost _invPost = new fsInvPost(); _invPost.InUsePreCalc = true; _invPost.InAllowNoImage = true; _OkToProcessInvoice = _invPost.Init(ref _dbType, ref _dbName, ref _dbServer, ref _dbLogin, ref _dbPassword); //Evaluate if the Init process was success to continue to add invoices if (_OkToProcessInvoice) { //if appropriate, set the transaction key associated to the batch header //_invPost.SetTrans(ref _transKey); var result = _invPost.CreateBuy("2", DateTime.Now, 0); if (result) { var transKey = _invPost.OutTransKey; _invPost.SetTrans(transKey); //if appropriate, set the total associate with the batch _invPost.SetTransTotals(ref _debitInvAmt, ref _creditInvAmt, ref _serviceFeeAmt, ref _escrowAmt, ref _expenseAmt, ref _recourseAmt, ref _netAmtToAdv); // Note - Repeat this line for every invoice to add to the batch _successful = ProcessInvoiceWithImage(_invPost, transKey, _debtorKey, _invNumber, _invAmount, _invDate, _invDescr, _enteredUserId, "C:\\test.jpg"); //Evaluate if the Invoice was processed successfully if (_successful) { //Complete Invoice Post Process _successful = false; _successful = _invPost.ReleaseBuy(); if (!_successful) { throw new Exception("Unsuccessfuly released purchase" + _invPost.OutErrorMsg); } _invPost.Wrap(); _successful = true; } } } return _successful; }