Exemplo n.º 1
0
    public void handleRBillingOnAccount(CCJOB job)
    {
        string CustNum = "";
        string CCAccountID = "";
        try
        {

            SAPCust sapcust = job_getCustomer(job);
            if (sapcust != null)
            {
                string amt = job.Amount;

                if (job_runCustomerTrans(sapcust, null, job, amt))
                {
                    if (job_AddPayment(job, null, sapcust, amt, job.CustomerID))
                    {
                        job_setNextRunDate(job.jobID, GetNextRunDate(job));
                    }
                }
            }

        }catch(Exception ex)
        {
            errorLog("Job failed on handleRBillingOnAccount. \r\n" +
               "JobID:" + job.jobID + "\r\n" +
                "CustNum:" + CustNum + "\r\n" +
                "CCAcountID:" + CCAccountID + "\r\n" +
               ex.Message);
        }
    }
Exemplo n.º 2
0
    public void BatchPreauth(SAPbouiCOM.Form form)
    {
        try {
            if (cfgBatchPreauth != "Y")
            {
                return;
            }
            if (SBO_Application.MessageBox("Run pre-auth on selected orders?", 1, "Yes", "No") != 1)
            {
                return;
            }

            SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)form.Items.Item("10").Specific;
            for (int i = 1; i <= oMatrix.RowCount; i++)
            {
                SAPbouiCOM.CheckBox check = (SAPbouiCOM.CheckBox)oMatrix.Columns.Item("1").Cells.Item(i).Specific;
                if (check.Checked)
                {
                    string docnum             = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("11").Cells.Item(i).Specific).Value;
                    string customerid         = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("10").Cells.Item(i).Specific).Value;
                    int    docentry           = getDocEntry("17", docnum, customerid);
                    SAPbobsCOM.Documents oDoc = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
                    if (oDoc.GetByKey(docentry))
                    {
                        if (oDoc.DocumentStatus == SAPbobsCOM.BoStatus.bost_Close)
                        {
                            SBO_Application.SetStatusBarMessage("eBizCharge Batch pre-auth sales order : " + docnum + " is closed.", SAPbouiCOM.BoMessageTime.bmt_Medium, true);
                        }
                        else
                        {
                            SAPCust sapcust = getCustomerByID(customerid, "");
                            if (sapcust == null)
                            {
                                SBO_Application.SetStatusBarMessage("eBizCharge Batch pre-auth sales order : " + docnum + " error customer: " + customerid + " has no payment method.", SAPbouiCOM.BoMessageTime.bmt_Medium, true);
                            }
                            else
                            {
                                if (isOrderPreauthed(docentry.ToString()))
                                {
                                    SBO_Application.SetStatusBarMessage("eBizCharge Batch pre-auth sales order : " + docnum + " order already pre-authed", SAPbouiCOM.BoMessageTime.bmt_Medium, true);
                                }
                                else
                                {
                                    BatchPreauth_PreAuthCustomer(oDoc, sapcust);
                                }
                            }
                        }
                    }
                    else
                    {
                        SBO_Application.SetStatusBarMessage("eBizCharge Batch pre-auth can not retrieve sales order : " + docnum + ". " + oCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
        }
    }
Exemplo n.º 3
0
    public void handleRBillingInvoice(CCJOB job)
    {
        string CustNum = "";
        string CCAccountID = "";
        try
        {
            int invID = getDocEntry("13", job.InvoiceID.ToString(), job.CustomerID);
            SAPbobsCOM.Documents oDoc = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
            if (!oDoc.GetByKey(invID))
            {
                string err = string.Format("Job {0} failed. Invoice ID: {1} not found", job.jobID, job.InvoiceID);
                job.Result = err;
                job.LastRunDate = DateTime.Today;
                update(job);
                errorLog(err);
                return;
            }
            SAPCust sapcust = job_getCustomer(job);
            if (sapcust != null)
            {
                string amt = job.Amount;
                double balance = getBalance(invID.ToString());
                if (balance == 0)
                {
                    job.EndDate = DateTime.Today;
                    job.LastRunDate = DateTime.Today;
                    job.Result = "Invoice closed";
                    update(job);
                    amt = "";
                }
                else if (balance < getDoubleValue(amt))
                    amt = balance.ToString();
                if (amt != "")
                {
                    if (job_runCustomerTrans(sapcust, oDoc, job, amt))
                    {
                        if (job_AddPayment(job, oDoc, sapcust, amt))
                        {
                            job_setNextRunDate(job.jobID, GetNextRunDate(job));
                        }
                    }
                }
            }

        }catch(Exception ex)
        {
            errorLog("Job failed on handleRBillingInvoice. \r\n" +
                "JobID:" + job.jobID + "\r\n" +
                "InvoiceID:" + job.InvoiceID + "\r\n" +
                 "CustNum:" + CustNum + "\r\n" +
                "CCAcountID:" + CCAccountID + "\r\n" +
               ex.Message);
            job.Result = "Failed. " + ex.Message;
            job.EndDate = DateTime.Today;
            update(job);
        }
    }
Exemplo n.º 4
0
    private void PaymentMeansFormHandler(SAPbouiCOM.Form form, SAPbouiCOM.ItemEvent pVal)
    {
        try
        {
            if (pVal.BeforeAction)
            {
                switch (pVal.EventType)
                {
                case SAPbouiCOM.BoEventTypes.et_FORM_LOAD:
                    PMCustID = getCustomerID();
                    if (PMCustID == "")
                    {
                        SBO_Application.MessageBox("Please select a customer first");
                        form.Visible = false;
                        return;
                    }
                    AddTab(form, panePM, "eBizCharge", "5");
                    AddCCPMFormField(form, paneBP);
                    form.Items.Item("5").Visible = false;
                    reload(form, PMCustID, ref PMCustList, ref PMSAPCust);
                    break;
                }
            }
            else
            {
                switch (pVal.EventType)
                {
                case SAPbouiCOM.BoEventTypes.et_FORM_LOAD:
                    currentForm = form;
                    tProcess    = new Thread(ThreadProc);
                    tProcess.Start();

                    break;

                case SAPbouiCOM.BoEventTypes.et_COMBO_SELECT:
                {
                    switch (pVal.ItemUID)
                    {
                    case cbPaymentMethod:
                        PMSAPCust = getCCInfoSelect(form, PMCustList);
                        populateCCInfo(form, PMSAPCust);

                        break;
                    }
                }
                break;

                case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED:
                    handlePMItemPress(form, pVal);
                    break;
                }
            }
        }catch (Exception ex)
        {
            errorLog(ex);
        }
    }
    /*
    private void setActive(SAPbouiCOM.Form form,string id)
    {
        try {
            var q = from a in db.CCCUSTs
                    where a.CustomerID == getLabelCaption(form, stRecordID)
                    select a;
            if (q.Count() > 0)
            {
                foreach (CCCUST cust in q)
                {
                    if (cust.recID.ToString() == id) // selSAPCust.cccust.recID)
                        cust.active = 'Y';
                    else
                        cust.active = 'N';
                }
                db.SubmitChanges();
            }
        }
        catch(Exception ex)
        {
            errorLog(ex);
        }
    }*/
    private bool loadFormData(SAPbouiCOM.Form form, ref SAPCust cust, bool bPaymentForm)
    {
        try
        {
            handleSwipe(form);
            if (cust == null)
                cust = new SAPCust();
            if (cust.custObj == null)
            {
                cust.custObj = createCustObj();
            }
            if (cust.cccust == null)
                cust.cccust = new CCCUST();
            cust.custObj.BillingAddress.FirstName = getFirstName( getFormEditVal(form,editHolderName) );
            cust.custObj.BillingAddress.LastName = getLastName(getFormEditVal(form,editHolderName));
            cust.custObj.BillingAddress.Street = getFormEditVal(form,editHolderAddr);
            cust.custObj.BillingAddress.City = getFormEditVal(form,editHolderCity);
            cust.custObj.BillingAddress.State = getFormEditVal(form,editHolderState);
            cust.custObj.BillingAddress.Zip = getFormEditVal(form, editHolderZip);
            if(getFormEditVal(form, editCardNum) != "")
            {
                cust.custObj.PaymentMethods[0].MethodType="cc";
                cust.custObj.PaymentMethods[0].CardNumber = getFormEditVal(form, editCardNum);
                cust.custObj.PaymentMethods[0].CardExpiration = getFormEditVal(form, editCardExpDate);
                cust.custObj.PaymentMethods[0].MethodName = cust.custObj.BillingAddress.FirstName + " " + cust.custObj.BillingAddress.LastName;
           }
            if(getFormEditVal(form, editCheckAccount) != "")
            {
                cust.custObj.PaymentMethods[0].MethodType="check";
                cust.custObj.PaymentMethods[0].Account = getFormEditVal(form, editCheckAccount);
                cust.custObj.PaymentMethods[0].Routing = getFormEditVal(form, editCheckRouting);
            }
            if(bPaymentForm)
            {
                cust.SaveCard = getComboBoxVal(form, cbCCSave);
                if(cfgAutoSelectAccount == "N")
                {
                    cust.CCAccount = getComboBoxVal(form, cbCCAccount);
                    if (cust.CCAccount.IndexOf("-") >= 0)
                        cust.CCAccount = cust.CCAccount.Substring(0, cust.CCAccount.IndexOf("-")).Trim();

                }
                else
                {

                    cust.CCAccount = GetCreditCardCode(cust.custObj.PaymentMethods[0].CardNumber, !(getButtonCaption(form, "1") == "Credit")).ToString();
                    if (cust.CCAccount == "0")
                        return false;
                }
            }
        }catch(Exception ex)
        {
            errorLog(ex);
        }
        return true;
    }
Exemplo n.º 6
0
    public bool job_AddPayment( CCJOB job , SAPbobsCOM.Documents oDoc, SAPCust cust, string amt = "", string customerID = "")
    {
        try
        {
            double dtotal = 0;
            if(oDoc != null)
                dtotal = oDoc.DocTotal;
            if (amt != "")
                dtotal = getDoubleValue(amt);
            SAPbobsCOM.Payments oPmt = (SAPbobsCOM.Payments)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments);
            int bplid = getBranchIdFromINV(oDoc.DocEntry.ToString());
            if (bplid != 0)
                oPmt.BPLID = bplid;
            if (oDoc != null)
            {
                oPmt.Invoices.DocEntry = oDoc.DocEntry;
                oPmt.Invoices.InvoiceType = SAPbobsCOM.BoRcptInvTypes.it_Invoice;
                oPmt.CardCode = oDoc.CardCode;
                oPmt.Invoices.SumApplied = dtotal;
            }
            else
                oPmt.CardCode = customerID;
            oPmt.DocDate = DateTime.Now;
            oPmt.Remarks = "eBizCharge Payment On Account Recurring Billing " + confirmNum;
            //oPmt.TransferDate = DateTime.Now;
            oPmt.DocTypte = SAPbobsCOM.BoRcptTypes.rCustomer;
            AddCreditCardPayment(oPmt, cust, dtotal, true);
            int r = oPmt.Add();
            if (r != 0)
            {
                errorLog("Job Failed on Add Payment. ID:" + job.jobID + "\r\n" +
                    "OrderID:" + job.OrderID + "\r\n" +
                    "CCAcountID:" + cust.cccust.CCAccountID + "\r\n" +
                    getErrorString());
                voidCustomer(confirmNum);
                job.Result = "Failed. " + getErrorString();
                job.LastRunDate = DateTime.Today;
                update(job);
                return false;
            }
            CCTRANUpdateIncomingPaymentID(confirmNum);
        }
        catch (Exception ex)
        {
            errorLog(ex);
            job.Result = "Failed. " +ex.Message;
            job.LastRunDate = DateTime.Today;
            update(job);
            voidCustomer(confirmNum);
            return false;

        }
        return true;
    }
 private void HandleSelect(SAPbouiCOM.Form form)
 {
     if (getComboBoxVal(form, cbPaymentMethod) == "New Card" || getComboBoxVal(form, cbPaymentMethod) == "New eCheck")
     {
         populateCustFormFromDB(form);
     }
     else
     {}
         selSAPCust = getCCInfoSelect(form, SAPCustList);
         populateCCInfo(form, selSAPCust);
     }
Exemplo n.º 8
0
    public void handleRBillingOrder(CCJOB job)
    {
        string refNum = "";
        int CCAccountID = 0;
        try {
            SAPbobsCOM.Documents oRefDoc = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
            if (!oRefDoc.GetByKey((int)job.OrderID))
            {
                string err = string.Format("Job {0} failed. Order ID: {1} not found", job.jobID, job.OrderID);
                job.Result = err;
                job.LastRunDate = DateTime.Today;
                update(job);
                errorLog(err);
                return;
            }
            int invID = job_createInvoice(oRefDoc, job);
            if (invID != 0)
            {
                SAPbobsCOM.Documents oDoc = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
                oDoc.GetByKey(invID);

                job_getInfoformTrans(job, ref refNum);
                SAPCust sapcust = job_getCustomer(job);

                if (sapcust != null)
                {
                    if (job_runCustomerTrans(sapcust, oDoc, job))
                    {
                        if (job_AddPayment(job, oDoc, sapcust))
                        {

                            job_setNextRunDate(job.jobID, GetNextRunDate(job));
                        }
                    }
                }
            }

        }catch(Exception ex)
        {
            errorLog("Job failed on handleRBillingOrder. \r\n" +
                "JobID:" + job.jobID + "\r\n" +
                 "OrderID:" + job.OrderID + "\r\n" +
                  "CustNum:" + CustNum + "\r\n" +
                 "CCAcountID:" + CCAccountID + "\r\n" +
                ex.Message);
            job.Result = "Failed. " + ex.Message;
            job.LastRunDate = DateTime.Today;
            update(job);
        }
    }
Exemplo n.º 9
0
    private bool Batch_runCustomRequest(CustomerTransactionRequest req, SAPCust sapcust, string orderid, string invoiceid, ref string refNum)
    {
        try
        {
            req.CustReceipt      = cfgsendCustomerEmail == "Y" ? true : false;
            req.CustReceiptName  = "vterm_customer";
            req.CustReceiptEmail = sapcust.custObj.Email;
            //form.Freeze(true);
            req.Details.Subtotal = 0;
            trace("Batch_runCustomRequest: command=" + req.Command + ", amount = " + req.Details.Amount + ", tax=" + req.Details.Tax + ",Subtotal=" + req.Details.Subtotal + ",shipping=" + req.Details.Shipping + ",Discount=" + req.Details.Discount);

            SecurityToken       token = getToken(sapcust.cccust.CCAccountID);
            TransactionResponse resp  = new TransactionResponse();

            resp = ebiz.runCustomerTransaction(token, sapcust.custObj.CustomerToken, sapcust.custObj.PaymentMethodProfiles[0].MethodID, req);
            trace("Batch_runCustomRequest: refNum = " + resp.RefNum + ", error=" + resp.Error);


            if (sapcust != null)
            {
                refNum = resp.RefNum;
                try
                {
                    if (resp.ResultCode == "D")
                    {
                        updateCustDeclined(sapcust.cccust.recID, "Y");
                    }
                    if (resp.ResultCode == "A")
                    {
                        updateCustDeclined(sapcust.cccust.recID, "N");
                    }
                }
                catch (Exception ex)
                {
                    errorLog(ex);
                }
            }

            logCustomTransaction(req, resp, sapcust, orderid, invoiceid);
            return(Batch_HandleResponse(resp, sapcust, ref refNum));
        }
        catch (Exception ex)
        {
            errorLog(ex);
            SBO_Application.MessageBox(ex.Message);
        }
        return(false);
    }
Exemplo n.º 10
0
    public SAPCust job_getCustomer(CCJOB job)
    {
        SAPCust sapcust = new SAPCust();
        try
        {
                 CCCUST c = null;
                List<CCCUST> q = findCCCust(string.Format(" where \"U_CustomerID\"='{0}' AND \"U_methodDescription\"='{1}'",job.CustomerID, job.PaymentID ));
                if(q.Count() == 0)
                {
                    List<CCCUST> q2 = findCCCust(string.Format(" where \"U_CustomerID\"='{0}'", job.CustomerID));
                    foreach (CCCUST c1 in q2)
                        c = c1;

                }
                else
                {
                    foreach (CCCUST c1 in q)
                        c = c1;
                }
                if(c == null)
                {
                    string err = "No payment method found";
                    job.Result = err;
                    job.LastRunDate = DateTime.Today;
                    update(job);
                    return null;
                }
                sapcust.cccust = c;
            string id = "";
                string cardcode = getCardAcctByCustNum(c.CustNum, ref id);
                SecurityToken token = getToken(cardcode);
                sapcust.custObj = ebiz.GetCustomer(token, c.CustomerID, null);
                return sapcust;

        }
        catch (Exception ex)
        {
            errorLog("Failed to Create Customer Obj." +
                "\r\nJobID:" + job.jobID +
                "\r\n" + ex.Message);
            job.Result = "Failed on get payment method";
            job.LastRunDate = DateTime.Today;
            update(job);

        }
        return null;
    }
Exemplo n.º 11
0
    private bool Batch_HandleResponse(TransactionResponse resp, SAPCust sapcust, ref string refNum)
    {
        try
        {
            if (resp.ResultCode == "A")
            {
                return(true);
            }
            else if (resp.Error.ToLower() == "approved")
            {
                return(true);
            }
            else
            {
                string msg = "";
                if (sapcust != null)
                {
                    if (sapcust.custObj.PaymentMethodProfiles[0].MethodType == "check")
                    {
                        msg = "Can not process your transaction for checking account: " + sapcust.custObj.PaymentMethodProfiles[0].Account + ".\r\n" + resp.Error;
                    }
                    else
                    {
                        msg = "Can not process your transaction for card: " + sapcust.custObj.PaymentMethodProfiles[0].CardNumber + ".\r\n" + resp.Error;
                    }
                }
                else
                {
                    msg = "Can not process your transaction for card.\r\n" + resp.Error;
                }

                SBO_Application.SetStatusBarMessage("eBizCharge Batch processing failed. " + msg, SAPbouiCOM.BoMessageTime.bmt_Medium, true);


                return(false);
            }
        }
        catch (Exception ex)
        {
            errorLog(ex);
        }
        return(false);
    }
Exemplo n.º 12
0
    public bool BatchPreauth_PreAuthCustomer(SAPbobsCOM.Documents doc, SAPCust sapcust)
    {
        try
        {
            CustomerTransactionRequest req = Batch_createCustomRequest(doc);
            req.CustReceipt      = cfgsendCustomerEmail == "Y" ? true : false;
            req.CustReceiptName  = "vterm_customer";
            req.CustReceiptEmail = sapcust.custObj.Email;

            req.Command = "cc:authonly";
            if (req.Command == "cc:authonly" && cfgPreAuthEmail != "Y")
            {
                req.CustReceipt = false;
            }
            if (req.CustReceiptEmail == "")
            {
                req.CustReceipt = false;
            }
            string refNum = "";
            if (Batch_runCustomRequest(req, sapcust, doc.DocEntry.ToString(), "", ref refNum))
            {
                confirmNum = refNum;
                BatchPreAuthUpdateTrans(doc.DocEntry, doc.CardCode, refNum);
                SBO_Application.SetStatusBarMessage("eBizCharge Batch pre-auth sales order : " + doc.DocNum + " approved. Approval Code:" + refNum + ", Amount:" + doc.DocTotal.ToString(), SAPbouiCOM.BoMessageTime.bmt_Medium, false);
            }
            else
            {
                return(false);
            }
        }
        catch (Exception ex)
        {
            errorLog(ex);
        }
        return(true);
    }
Exemplo n.º 13
0
    public bool job_runCustomerTrans(SAPCust sapcust, SAPbobsCOM.Documents oDoc, CCJOB job, string amt ="")
    {
        try
        {
            string cmd = "cc:sale";
            if (sapcust.custObj.PaymentMethodProfiles[0].MethodType == "check")
                cmd = "check";
            confirmNum = "";

            CustomerTransactionRequest req = job_createCustomRequest(job, oDoc, amt);
            req.Command = cmd;
            trace("Job_runCustomRequest: amount = " + req.Details.Amount + ", tax=" + req.Details.Tax + ",Subtotal=" + req.Details.Subtotal + ",shipping=" + req.Details.Shipping + ",Discount=" + req.Details.Discount +
             string.Format("runCustomerTrans, token={0}, method={1}:{2}", sapcust.custObj.CustomerToken, sapcust.custObj.PaymentMethodProfiles[0].MethodID, sapcust.custObj.PaymentMethodProfiles[0].CardNumber));
            req.CustReceipt = cfgsendCustomerEmail == "Y" ? true : false;
            req.CustReceiptName = "vterm_customer";
            req.CustReceiptEmail = sapcust.custObj.Email;
            if (req.Command == "cc:authonly" && cfgPreAuthEmail != "Y")
                req.CustReceipt = false;
            if (req.CustReceiptEmail == "")
                req.CustReceipt = false;
            SecurityToken token = getToken(sapcust.cccust.CCAccountID);
            TransactionResponse resp = new TransactionResponse();
            resp = ebiz.runCustomerTransaction(token, sapcust.custObj.CustomerToken, sapcust.custObj.PaymentMethodProfiles[0].MethodID, req);
            confirmNum = resp.RefNum;
            sendReceipt(token, sapcust, resp);
            int invoiceID = 0;
            if (oDoc != null)
                invoiceID = oDoc.DocEntry;
            job_logCustomTransaction(req, resp, sapcust, job, invoiceID.ToString());
            if (resp.Error.ToLower() == "approved")
            {
                job.Result = "Success";
                job.LastRunDate = DateTime.Today;
                update(job);
                return true;
            }
            else
            {
                if (resp.ResultCode == "D")
                {
                    if (req.CustReceiptEmail != "" && req.CustReceiptEmail != null && cfgCustomerReceipt != "")
                    {

                        try
                        {
                            EmailReceiptResponse emresp = ebiz.EmailReceipt(token, resp.RefNum, resp.RefNum, cfgCustomerReceipt, req.CustReceiptEmail);

                            if (emresp.ErrorCode == 0)
                            {
                                showStatus("Declined receipt sent.", SAPbouiCOM.BoMessageTime.bmt_Medium,false);
                            }
                            else
                                showStatus("Failed to send declined receipt.\r\n" + resp.Error, SAPbouiCOM.BoMessageTime.bmt_Medium,true);

                        }
                        catch (Exception ex2)
                        {
                            showStatus("Failed to send receipt.\r\n" + ex2.Message, SAPbouiCOM.BoMessageTime.bmt_Medium, false);
                        }

                    }
                }
                string err = "Job Failed. ID:" + job.jobID + "\r\n" + resp.Error;
                job.Result = err;
                job.LastRunDate = DateTime.Today;
                update(job);
                errorLog(err);
                return false;
            }

        }
        catch (Exception ex)
        {
            string err = "Job Failed. ID:" + job.jobID + "\r\n" + ex.Message;
            job.Result = err;
            job.LastRunDate = DateTime.Today;
            update(job);
            errorLog(ex);

            return false;
        }
    }
Exemplo n.º 14
0
    private void ExpImportThread()
    {
        try
        {
            oCustImpForm.Items.Item(btnExpFImp).Enabled = false;
            oCustImpForm.Items.Item(btnFImp).Enabled    = false;
            oCustImpForm.Items.Item(btnFind).Enabled    = false;
            oCustImpForm.Items.Item(btnImp).Enabled     = false;

            List <ImportData> dataList = new List <ImportData>();
            string            fn       = getFormItemVal(oCustImpForm, editExpFileName);

            var fileLines = File.ReadAllLines(fn).Skip(1).ToList();
            foreach (string line in fileLines)
            {
                string[]   i    = line.Split('\t');
                ImportData data = new ImportData();
                try
                {
                    data.CustomerID = i[0];
                    data.CustNum    = i[1];

                    /*
                     * if(data.CustomerID != "")
                     * {
                     *  data.CustomerID = "A1";
                     *  data.CustNum = "8545319";
                     * }
                     */
                }
                catch (Exception)
                { }
                if (data.CustomerID != null && data.CustomerID != "")
                {
                    dataList.Add(data);
                }
            }
            foreach (ImportData imp in dataList)
            {
                SAPCust sapcust = new SAPCust();
                try
                {
                    sapcust.cccust            = new CCCUST();
                    sapcust.cccust.CustomerID = imp.CustomerID;
                    sapcust.cccust.GroupName  = getGroupName(imp.CustomerID);
                    string code = "";
                    sapcust.cccust.CardName    = getCardName(sapcust.cccust.GroupName, sapcust.cccust.cardType, "", ref code);
                    sapcust.cccust.CCAccountID = code;
                    sapcust.cccust.CustNum     = imp.CustNum;
                    SecurityToken token = getToken(sapcust.cccust.CCAccountID);
                    sapcust.custObj           = ebiz.GetCustomer(token, imp.CustomerID, "");
                    sapcust.cccust.city       = sapcust.custObj.BillingAddress.City;
                    sapcust.cccust.email      = sapcust.custObj.Email;
                    sapcust.cccust.street     = sapcust.custObj.BillingAddress.Address1;
                    sapcust.cccust.state      = sapcust.custObj.BillingAddress.State;
                    sapcust.cccust.zip        = sapcust.custObj.BillingAddress.ZipCode;
                    sapcust.cccust.firstName  = sapcust.custObj.BillingAddress.FirstName;
                    sapcust.cccust.lastName   = sapcust.custObj.BillingAddress.LastName;
                    sapcust.cccust.MethodID   = sapcust.custObj.PaymentMethodProfiles[0].MethodID;
                    sapcust.cccust.methodName = sapcust.custObj.PaymentMethodProfiles[0].MethodName;
                    try
                    {
                        if (imp.defaultCard != null && imp.defaultCard != "")
                        {
                            sapcust.cccust.@default = imp.defaultCard[0];
                        }
                    }
                    catch (Exception) { }


                    CCCUST ccust = sapcust.cccust;
                    int    id    = getNextTableID("@CCCUST");
                    string desc  = sapcust.custObj.BillingAddress.FirstName + " " + sapcust.custObj.BillingAddress.LastName;
                    if (sapcust.custObj.PaymentMethodProfiles[0].MethodName != "" && sapcust.custObj.PaymentMethodProfiles[0].MethodName != null)
                    {
                        desc = sapcust.custObj.PaymentMethodProfiles[0].MethodName;
                    }
                    if (sapcust.custObj.PaymentMethodProfiles[0].MethodType == "check")
                    {
                        sapcust.cccust.methodDescription = id.ToString() + "_" + sapcust.custObj.PaymentMethodProfiles[0].Routing + " " + sapcust.custObj.PaymentMethodProfiles[0].Account + "(" + desc + ")";
                        sapcust.cccust.checkingAccount   = sapcust.custObj.PaymentMethodProfiles[0].Account;
                        sapcust.cccust.routingNumber     = sapcust.custObj.PaymentMethodProfiles[0].Routing;
                    }
                    else
                    {
                        sapcust.cccust.expDate           = DateTime.Parse(sapcust.custObj.PaymentMethodProfiles[0].CardExpiration).ToString("MMyy");
                        sapcust.cccust.cardNum           = sapcust.custObj.PaymentMethodProfiles[0].CardNumber;
                        sapcust.cccust.methodDescription = id.ToString() + "_" + sapcust.custObj.PaymentMethodProfiles[0].CardNumber + " " + sapcust.custObj.PaymentMethodProfiles[0].CardExpiration + "(" + desc + ")";
                        sapcust.cccust.cardType          = sapcust.custObj.PaymentMethodProfiles[0].CardType;
                        sapcust.cccust.CardName          = getCardName(sapcust.cccust.GroupName, sapcust.cccust.cardType, "", ref code);
                        sapcust.cccust.CCAccountID       = code;
                    }
                    insert(ccust);
                    SetText("\r\n" + string.Format("Customer {0} card {1} added", sapcust.cccust.CustomerID, sapcust.cccust.cardNum));
                }
                catch (Exception ex)
                {
                    SetText("\r\n" + string.Format("Failed to add customer {0} card {1}. {2}", sapcust.cccust.CustomerID, sapcust.cccust.cardNum, ex.Message));
                }
            }
            SetText("\r\nImport Completed.");
        }
        catch (Exception ex)
        {
            showMessage(ex.Message);
        }
        finally
        {
            try
            {
                oCustImpForm.Items.Item(btnExpFImp).Enabled = true;
                oCustImpForm.Items.Item(btnFind).Enabled    = true;
                oCustImpForm.Items.Item(btnFImp).Enabled    = true;
                oCustImpForm.Items.Item(btnFind).Enabled    = true;
                oCustImpForm.Items.Item(btnImp).Enabled     = true;
            }
            catch (Exception) { }
        }
    }
Exemplo n.º 15
0
    private void importThread()
    {
        try
        {
            oCustImpForm.Items.Item(btnFImp).Enabled = false;
            oCustImpForm.Items.Item(btnFind).Enabled = false;
            oCustImpForm.Items.Item(btnImp).Enabled  = false;

            List <ImportData> dataList = new List <ImportData>();
            string            fn       = getFormItemVal(oCustImpForm, editFileName);

            var fileLines = File.ReadAllLines(fn).Skip(1).ToList();
            foreach (string line in fileLines)
            {
                string[]   i    = line.Split('\t');
                ImportData data = new ImportData();
                try
                {
                    data.CustomerID     = i[0];
                    data.CompanyName    = i[1];
                    data.FirstName      = i[2];
                    data.LastName       = i[3];
                    data.Street         = i[4];
                    data.Street2        = i[5];
                    data.Zip            = i[6];
                    data.City           = i[7];
                    data.State          = i[8];
                    data.Phone          = i[9];
                    data.Fax            = i[10];
                    data.Email          = i[11];
                    data.URL            = i[12];
                    data.CardNumber     = i[13];
                    data.CardExpiration = i[14];
                    data.MethodName     = i[15];
                    if (i.Length >= 16)
                    {
                        data.defaultCard = i[16];
                    }
                }
                catch (Exception)
                { }
                if (data.CustomerID != null && data.CustomerID != "")
                {
                    dataList.Add(data);
                }
            }
            foreach (ImportData imp in dataList)
            {
                SAPCust sapcust = new SAPCust();
                sapcust.cccust            = new CCCUST();
                sapcust.cccust.city       = imp.City;
                sapcust.cccust.email      = imp.Email;
                sapcust.cccust.street     = imp.Street;
                sapcust.cccust.state      = imp.State;
                sapcust.cccust.zip        = imp.Zip;
                sapcust.cccust.firstName  = imp.FirstName;
                sapcust.cccust.lastName   = imp.LastName;
                sapcust.cccust.CustomerID = imp.CustomerID;
                sapcust.cccust.GroupName  = getGroupName(imp.CustomerID);
                sapcust.cccust.cardType   = getCardType(imp.CardNumber);
                sapcust.cccust.methodName = imp.MethodName;
                try
                {
                    if (imp.defaultCard != null && imp.defaultCard != "")
                    {
                        sapcust.cccust.@default = imp.defaultCard[0];
                    }
                }
                catch (Exception) { }
                string code = "";
                sapcust.cccust.CardName    = getCardName(sapcust.cccust.GroupName, sapcust.cccust.cardType, "", ref code);
                sapcust.cccust.CCAccountID = code;
                sapcust.cccust.cardNum     = imp.CardNumber;
                sapcust.cccust.expDate     = imp.CardExpiration;
                CCCUST cust = sapcust.cccust;
                sapcust.custObj = new  Customer();
                sapcust.custObj.BillingAddress                          = new Address();
                sapcust.custObj.Email                                   = cust.email;
                sapcust.custObj.BillingAddress.FirstName                = cust.firstName;
                sapcust.custObj.BillingAddress.LastName                 = cust.lastName;
                sapcust.custObj.BillingAddress.State                    = cust.state;
                sapcust.custObj.BillingAddress.City                     = cust.city;
                sapcust.custObj.BillingAddress.ZipCode                  = cust.zip;
                sapcust.custObj.BillingAddress.Address1                 = cust.street;
                sapcust.custObj.PaymentMethodProfiles                   = new PaymentMethodProfile[1];
                sapcust.custObj.PaymentMethodProfiles[0]                = new PaymentMethodProfile();
                sapcust.custObj.PaymentMethodProfiles[0].CardNumber     = cust.cardNum;
                sapcust.custObj.PaymentMethodProfiles[0].CardType       = cust.cardType;
                sapcust.custObj.PaymentMethodProfiles[0].CardExpiration = cust.expDate;
                sapcust.custObj.PaymentMethodProfiles[0].CardCode       = cust.cardCode;
                sapcust.custObj.PaymentMethodProfiles[0].MethodName     = imp.MethodName;
                sapcust.custObj.PaymentMethodProfiles[0].MethodType     = "cc";
                if (AddCustomer(ref sapcust))
                {
                    SetText("\r\n" + string.Format("Customer {0} card {1} added", sapcust.cccust.CustomerID, sapcust.cccust.cardNum));
                }
                else
                {
                    SetText("\r\n" + string.Format("Failed to add Customer {0} card {1}", sapcust.cccust.CustomerID, sapcust.cccust.cardNum));
                }
            }
            SetText("\r\nImport Completed.");
        }
        catch (Exception ex)
        {
            showMessage(ex.Message);
        }
        finally
        {
            try
            {
                oCustImpForm.Items.Item(btnFImp).Enabled = true;
                oCustImpForm.Items.Item(btnFind).Enabled = true;
                oCustImpForm.Items.Item(btnImp).Enabled  = true;
            }
            catch (Exception) { }
        }
    }
    private void HandleCCLogSelect(SAPbouiCOM.Form form)
    {
        try
        {
            string CustomerID = getCustomerID(form);

            SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)form.Items.Item(mxtCCLog).Specific;
            for (int i = 1; i <= oMatrix.RowCount; i++)
            {
                if (oMatrix.IsRowSelected(i))
                {
                    string id      = getMatrixItem(oMatrix, "ccTRANSID", i);
                    string cmd     = getMatrixItem(oMatrix, "command", i);
                    string refnum  = getMatrixItem(oMatrix, "RefNum", i);
                    string SOID    = getMatrixItem(oMatrix, "OrderID", i);
                    string custNum = getMatrixItem(oMatrix, "custNum", i);

                    if (cmd == "cc:authonly" && form.TypeEx == FORMSALESORDER)
                    {
                        bAuto = false;
                        if (SBO_Application.MessageBox("Void preauth transaction " + refnum + "?", 1, "Yes", "No") == 1)
                        {
                            if (voidTransaction(refnum))
                            {
                                voidUpdateTrans(id);
                                populateLog(form);
                            }
                        }
                    }

                    if (cmd == "cc:authonly" || cmd == "cc:sale" || cmd == "check")
                    {
                        bAuto = false;
                        SAPCust sapcust = getCustomerByID(CustomerID, refnum);
                        string  email   = getFormItemVal(form, editEmail);
                        if (email == "")
                        {
                            email = getCustEmail(CustomerID);
                        }
                        if (email != "" && email != null)
                        {
                            if (SBO_Application.MessageBox("Send email receipt to " + email + "?", 1, "Yes", "No") == 1)
                            {
                                try
                                {
                                    SecurityToken        token = getToken(sapcust.cccust.CCAccountID);
                                    EmailReceiptResponse resp  = ebiz.EmailReceipt(token, refnum, refnum, "vterm_customer", email);

                                    if (resp.ErrorCode == 0)
                                    {
                                        SBO_Application.MessageBox("Receipt sent.");
                                    }
                                    else
                                    {
                                        SBO_Application.MessageBox("Failed to send receipt.\r\n" + resp.Error);
                                    }
                                }
                                catch (Exception ex2)
                                {
                                    SBO_Application.MessageBox("Failed to send receipt.\r\n" + ex2.Message);
                                }
                            }
                        }
                    }
                }
            }
        }catch (Exception ex)
        {
            errorLog(ex);
        }
    }
Exemplo n.º 17
0
    private void job_logCustomTransaction(CustomerTransactionRequest req, TransactionResponse resp, SAPCust sapcust, CCJOB job, string InvoiceID = "")
    {
        CCTRAN cctran = new CCTRAN();

        try
        {
            if (job.OrderID == null)
                job.OrderID = 0;
            if (job.InvoiceID == null)
                job.InvoiceID = 0;

            cctran.customerID = sapcust.cccust.CustomerID;
            cctran.CCAccountID = 0;
            cctran.jobID = (int)job.jobID;
            cctran.OrderID = job.OrderID.ToString();
            cctran.InvoiceID = InvoiceID;
            cctran.CreditMemoID = "";
            cctran.DownPaymentInvoiceID = "";
            if (sapcust != null)
            {
                try
                {
                    cctran.CCAccountID = int.Parse(sapcust.cccust.CCAccountID);
                    cctran.customerID = sapcust.cccust.CustomerID;
                    cctran.MethodID = sapcust.custObj.PaymentMethodProfiles[0].MethodID;
                    cctran.custNum = sapcust.cccust.CustNum;
                    cctran.crCardNum = sapcust.custObj.PaymentMethodProfiles[0].CardNumber;
                    cctran.CardHolder = sapcust.custObj.BillingAddress.FirstName + " " + sapcust.custObj.BillingAddress.LastName;
                }catch(Exception ex)
                {
                    errorLog(ex);
                }
            }
            cctran.Description = req.Details.Description;
            cctran.recID = req.Details.Invoice;
            cctran.acsUrl = resp.AcsUrl;
            cctran.authAmount = resp.AuthAmount.ToString();
            cctran.authCode = resp.AuthCode;
            cctran.avsResult = resp.AvsResult;
            cctran.avsResultCode = resp.AvsResultCode;
            cctran.batchNum = resp.BatchNum;
            cctran.batchRef = resp.BatchRefNum;
            cctran.cardCodeResult = resp.CardCodeResult;
            cctran.cardCodeResultCode = resp.CardCodeResultCode;
            cctran.cardLevelResult = resp.CardLevelResult;
            cctran.cardLevelResultCode = resp.CardLevelResultCode;
            cctran.conversionRate = resp.ConversionRate.ToString();
            cctran.convertedAmount = resp.ConvertedAmount.ToString();
            cctran.convertedAmountCurrency = resp.ConvertedAmountCurrency.ToString();
            cctran.custNum = resp.CustNum;
            cctran.error = resp.Error;
            cctran.errorCode = resp.ErrorCode;
            cctran.isDuplicate = resp.isDuplicate.ToString();
            cctran.payload = resp.Payload;
            cctran.profilerScore = resp.ProfilerScore;
            cctran.profilerResponse = resp.ProfilerResponse;
            cctran.profilerReason = resp.ProfilerReason;
            cctran.refNum = resp.RefNum;
            cctran.remainingBalance = resp.RemainingBalance.ToString();
            cctran.result = resp.Result;
            cctran.resultCode = resp.ResultCode;
            cctran.status = resp.Status;
            cctran.statusCode = resp.StatusCode;
            cctran.vpasResultCode = resp.VpasResultCode;
            cctran.recDate = DateTime.Now;//Use local time not server time
            cctran.command = req.Command;
            cctran.amount = req.Details.Amount.ToString();
            insert(cctran);
        }
        catch (Exception ex)
        {

            errorLog(ex);
        }
    }
Exemplo n.º 18
0
    public void checkePayPaidStatus(string custid)
    {
        try
        {
            if (custid == "" || custid == null)
            {
                return;
            }
            if (!IsPayFormCustomerExist(custid))
            {
                return;
            }
            SBO_Application.SetStatusBarMessage("Checking payment status for customer: " + custid + ". Please wait...", SAPbouiCOM.BoMessageTime.bmt_Medium, false);


            SecurityToken securityToken = getToken();

            Payment[] pmts = ebiz.SearchEbizWebFormReceivedPayments(securityToken, custid, DateTime.Today.AddDays(-90), DateTime.Today.AddDays(1), null, 0, 1000, "");
            foreach (Payment p in pmts)
            {
                List <CCPayFormInvoice> q = findCCPayFormInvoice(string.Format(" where \"U_InvoiceID\" = '{0}' and \"U_CustomerID\"='{1}'", p.InvoiceNumber, p.CustomerId));
                foreach (CCPayFormInvoice i in q)
                {
                    try
                    {
                        SAPbobsCOM.Documents oDoc = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
                        if (!oDoc.GetByKey(int.Parse(i.InvoiceGUID)))
                        {
                            errorLog("Inv not found: " + i.InvoiceGUID);
                            i.Status = "Invoice not found: " + i.InvoiceGUID;

                            update(i);
                            continue;
                        }
                        if (oDoc.DocumentStatus == SAPbobsCOM.BoStatus.bost_Close)
                        {
                            i.PaidAmount = p.PaidAmount;
                            i.PaidDate   = DateTime.Parse(p.DatePaid);
                            i.Status     = "Paid";
                            update(i);
                        }
                        else
                        {
                            string where = string.Format(" where \"U_CustomerID\"='{0}' and \"U_InvoiceID\"='{1}' and \"U_PaymentID\"='{2}'", p.CustomerId, p.InvoiceNumber, p.AuthCode);

                            var qcc = findCCPayFormPayment(where);
                            if (qcc.Count() == 0)
                            {
                                SAPbobsCOM.Payments oPmt = (SAPbobsCOM.Payments)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments);
                                int bplid = getBranchIdFromINV(i.InvoiceGUID);
                                if (bplid != 0)
                                {
                                    oPmt.BPLID = bplid;
                                }
                                oPmt.CardCode = i.CustomerID;
                                oPmt.DocDate  = DateTime.Now;
                                oPmt.Remarks  = "eBizCharge ePayment Form Payment";

                                oPmt.DocTypte             = SAPbobsCOM.BoRcptTypes.rCustomer;
                                oPmt.JournalRemarks       = "eBizCharge ePayment Form payment";
                                oPmt.Invoices.DocEntry    = int.Parse(i.InvoiceGUID);
                                oPmt.Invoices.InvoiceType = SAPbobsCOM.BoRcptInvTypes.it_Invoice;
                                oPmt.Invoices.SumApplied  = double.Parse(p.PaidAmount);
                                SAPCust sapcust = getCustomerByID(i.CustomerID, "");
                                AddCreditCardPayment(oPmt, sapcust, double.Parse(p.PaidAmount), true);
                                int r = oPmt.Add();
                                if (r != 0)
                                {
                                    errorLog("ePaymentForm Failed Payment. ID:" + i.CustomerID + "\r\n" +
                                             "InvoiceID:" + i.InvoiceGUID + "\r\n" +
                                             oCompany.GetLastErrorDescription());
                                }
                                else
                                {
                                    CCPayFormPayment pmt = new CCPayFormPayment();
                                    pmt.InvoiceID    = p.InvoiceNumber;
                                    pmt.CustomerID   = p.CustomerId;
                                    pmt.PaymentID    = p.AuthCode;
                                    pmt.Amount       = p.PaidAmount;
                                    pmt.DateImported = DateTime.Now;
                                    insert(pmt);
                                }
                            }
                            i.PaidAmount = p.PaidAmount;
                            i.PaidDate   = DateTime.Parse(p.DatePaid);
                            if (double.Parse(p.PaidAmount) < double.Parse(p.InvoiceAmount))
                            {
                                i.Status = EPAY_STATUS_PARTIAL;
                            }
                            else
                            {
                                i.Status = EPAY_STATUS_PAID;
                            }
                            update(i);
                        }
                    }
                    catch (Exception ex)
                    {
                        errorLog(ex);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            errorLog(ex);
        }
        SBO_Application.SetStatusBarMessage("Status check for customer: " + custid + " completed.", SAPbouiCOM.BoMessageTime.bmt_Medium, false);
    }
    private void reload(SAPbouiCOM.Form form, string customerID, ref List<SAPCust> list, ref SAPCust sel, bool bAll = false)
    {
        try
        {
           
            sel = new SAPCust();
            list = new List<SAPCust>();
            SAPbouiCOM.ComboBox oCB = form.Items.Item(cbPaymentMethod).Specific;
            try
            {
                while (oCB.ValidValues.Count > 0)
                    oCB.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index);
            }
            catch (Exception)
            { }
            oCB.ValidValues.Add("New Card", "New Card");
            oCB.ValidValues.Add("New eCheck", "New eCheck");
            var q = from a in db.CCCUSTs
                    where a.CustomerID == customerID
                    select a;
            if (q.Count() == 0)
            {
                int n = oCB.ValidValues.Count - 2;
                SBO_Application.SetStatusBarMessage("Number of record in combo= " + n.ToString(), SAPbouiCOM.BoMessageTime.bmt_Medium, false);
                
                oCB.Select("New Card");
                populateCustFromDB(form);
                SBO_Application.SetStatusBarMessage("Credit card for customer: " + getLabelCaption(form, stRecordID) + " loaded. No credit card record found", SAPbouiCOM.BoMessageTime.bmt_Medium, false);
                return;
            }
            if (q.Count() > 0)
            {
            
                bool hasDefault = false;
                foreach(CCCUST cust in q)
                {
                    if (cust.active == 'Y' || bAll)
                    {
                        SAPCust sapcust = new SAPCust();
                        sapcust.cccust = cust;
                        string id = cust.CustomerID + "_" + cust.recID.ToString();
                        sapcust.custObj = getCustomer(id);
                        if (sapcust.custObj.PaymentMethods.Count() == 0)
                        {
                            db.CCCUSTs.DeleteOnSubmit(cust);
                            db.SubmitChanges();
                        }
                        else
                        {
                            if(sapcust.custObj.PaymentMethods[0].MethodType == "check")
                                sapcust.key = cust.recID.ToString() + "_" + sapcust.custObj.PaymentMethods[0].Routing + " " + sapcust.custObj.PaymentMethods[0].Account + "(" + sapcust.custObj.BillingAddress.FirstName + " " + sapcust.custObj.BillingAddress.LastName + ")";
                            else
                                sapcust.key = cust.recID.ToString() + "_" + sapcust.custObj.PaymentMethods[0].CardNumber + " " + sapcust.custObj.PaymentMethods[0].CardExpiration + "(" + sapcust.custObj.BillingAddress.FirstName + " " + sapcust.custObj.BillingAddress.LastName + ")";
                            if (cust.Declined == 'Y')
                                sapcust.key = sapcust.key + ", Declined";
                            SAPbouiCOM.ValidValue v = oCB.ValidValues.Add(sapcust.key, sapcust.key);
                            list.Add(sapcust);
                            if (!hasDefault)
                                sel = sapcust;
                            if (cust.@default == 'Y')
                            {
                                hasDefault = true;
                                sel = sapcust;
                            }
                            

                        }
                    }
                }
            }
            if (sel.key != null)
                oCB.Select(sel.key);
            populateCCInfo(form, sel);
            SBO_Application.SetStatusBarMessage("Credit card for customer: " + getLabelCaption(form, stRecordID) + " loaded. " + oCB.ValidValues.Count + " credit card record(s) found", SAPbouiCOM.BoMessageTime.bmt_Medium, false);
        }catch(Exception ex)
        {
             errorLog(ex);
        }
   
    }
Exemplo n.º 20
0
    public void checkePayPaidStatus(string custid, string securityID = "")
    {
        SAPDBDataContext db = new SAPDBDataContext(connStr);

        try
        {
            if (custid == "" || custid == null)
            {
                return;
            }
            SAPbobsCOM.Documents oDoc = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
            string invType            = "Invoice";
            if (oePaymentFormForm != null)
            {
                invType = getFormItemVal(oePaymentFormForm, cbInvType);
                showStatus("Checking " + invType + " payment status for customer: " + custid + ". Please wait...", SAPbouiCOM.BoMessageTime.bmt_Medium, false);
            }
            else if (cfgConnectUseDP == "Y")
            {
                invType = "Down Payment";
            }
            showStatus("Checking payment status for customer: " + custid + ". Please wait...", SAPbouiCOM.BoMessageTime.bmt_Medium, false);
            if (invType == "Down Payment")
            {
                oDoc = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDownPayments);
            }
            string invSql = " OINV (NOLOCK) ";
            if (invType == "Down Payment")
            {
                invSql = " ODPI (NOLOCK) ";
            }
            SecurityToken securityToken = getTokenEx(custid, "", "", "");
            if (securityID != "")
            {
                securityToken.SecurityId = securityID;
            }

            Payment[] pmts = ebiz.SearchEbizWebFormReceivedPayments(securityToken, custid, DateTime.Today.AddDays(-90), DateTime.Today.AddDays(1), null, 0, 1000, "");
            trace(string.Format("ebiz.SearchEbizWebFormReceivedPayments found {0} for custid {1}", pmts.Count(), custid));

            foreach (Payment p in pmts)
            {
                trace(string.Format("eMail Form pmt = {0}, {1}, {2}, {3}, {4}", p.InvoiceNumber, p.CustomerId, p.RefNum, p.AuthCode, p.PaidAmount));
                if (p.InvoiceNumber == "Method Request")
                {
                    continue;
                }
                //Invoice inv = ebiz.GetInvoice(securityToken, p.DatePaid, "", p.InvoiceNumber, "");
                var q = from x in db.CCPayFormInvoices
                        where x.InvoiceID == p.InvoiceNumber
                        select x;
                if (q.Count() == 0)
                {
                    trace("EMAIL Form invoice with payment not found in CCPayFormInvoice invoice no. " + p.InvoiceNumber);

                    CCPayFormInvoice ccinv = new CCPayFormInvoice();
                    ccinv.CustomerID      = p.CustomerId;
                    ccinv.InvoiceID       = p.InvoiceNumber;
                    ccinv.InvoiceGUID     = getSQLInt(string.Format("select DocEntry from {0} where cardcode='{1}' and docnum = {2}", invSql, p.CustomerId, p.InvoiceNumber)).ToString();
                    ccinv.UploadedBalance = p.InvoiceAmount.ToString();
                    ccinv.PaidAmount      = "0";
                    ccinv.Status          = "Uploaded";
                    ccinv.UploadDate      = DateTime.Today;
                    db.CCPayFormInvoices.InsertOnSubmit(ccinv);
                    db.SubmitChanges();
                    q = from x in db.CCPayFormInvoices
                        where x.InvoiceID == p.InvoiceNumber
                        select x;
                }
                foreach (CCPayFormInvoice i in q)
                {
                    try
                    {
                        if (!oDoc.GetByKey(int.Parse(i.InvoiceGUID)))
                        {
                            errorLog("Inv not found: " + i.InvoiceGUID);
                            i.Status = "Invoice not found: " + i.InvoiceGUID;

                            db.SubmitChanges();
                            continue;
                        }
                        if (oDoc.DocumentStatus == SAPbobsCOM.BoStatus.bost_Close)
                        {
                            i.PaidAmount = p.PaidAmount;
                            i.PaidDate   = DateTime.Parse(p.DatePaid);
                            i.Status     = "Paid";
                            db.SubmitChanges();
                        }
                        else
                        {
                            var qcc = from x in db.CCPayFormPayments
                                      where x.CustomerID == p.CustomerId && x.InvoiceID == p.InvoiceNumber && x.PaymentID == p.AuthCode
                                      select x;
                            if (qcc.Count() == 0)
                            {
                                SAPbobsCOM.Payments oPmt = (SAPbobsCOM.Payments)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments);
                                int bplid = getBranchIdFromINV(p.InvoiceNumber);
                                if (bplid != 0)
                                {
                                    oPmt.BPLID = bplid;
                                }
                                oPmt.CardCode = i.CustomerID;
                                oPmt.DocDate  = DateTime.Now;
                                //  oPmt.Remarks = "eBizCharge ePayment Form Payment";

                                oPmt.DocTypte = SAPbobsCOM.BoRcptTypes.rCustomer;
                                // oPmt.JournalRemarks = "eBizCharge ePayment Form payment";
                                oPmt.Invoices.DocEntry    = int.Parse(i.InvoiceGUID);
                                oPmt.Invoices.InvoiceType = SAPbobsCOM.BoRcptInvTypes.it_Invoice;
                                if (oDoc.DocObjectCode == SAPbobsCOM.BoObjectTypes.oDownPayments)
                                {
                                    oPmt.Invoices.InvoiceType = SAPbobsCOM.BoRcptInvTypes.it_DownPayment;
                                }

                                oPmt.Invoices.SumApplied = getDoubleValue(p.PaidAmount);

                                SAPCust sapcust = getCustomerByID(i.CustomerID, "");
                                sapcust.cccust.CCAccountID = geteConnectCardCode(p.PaymentMethod);
                                AddCreditCardPayment(oPmt, sapcust, getDoubleValue(p.PaidAmount), true, p.RefNum);
                                int r = oPmt.Add();
                                if (r != 0)
                                {
                                    errorLog("ePaymentForm Failed Payment. ID:" + i.CustomerID + "\r\n" +
                                             "InvoiceID:" + i.InvoiceGUID + "\r\n" +
                                             oCompany.GetLastErrorDescription());
                                }
                                else
                                {
                                    CCPayFormPayment pmt = new CCPayFormPayment();
                                    pmt.InvoiceID    = p.InvoiceNumber;
                                    pmt.CustomerID   = p.CustomerId;
                                    pmt.PaymentID    = p.AuthCode;
                                    pmt.Amount       = p.PaidAmount;
                                    pmt.DateImported = DateTime.Now;
                                    db.CCPayFormPayments.InsertOnSubmit(pmt);
                                    db.SubmitChanges();
                                }
                            }
                            i.PaidAmount = p.PaidAmount;
                            i.PaidDate   = DateTime.Parse(p.DatePaid);
                            if (getDoubleValue(p.PaidAmount) < getDoubleValue(p.InvoiceAmount))
                            {
                                i.Status = EPAY_STATUS_PARTIAL;
                            }
                            else
                            {
                                i.Status = EPAY_STATUS_PAID;
                            }
                            db.SubmitChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        errorLog(ex);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            errorLog(ex);
        }
        showStatus("Status check for customer: " + custid + " completed.", SAPbouiCOM.BoMessageTime.bmt_Medium, false);
    }
    private void handleItemPress(SAPbouiCOM.Form form, SAPbouiCOM.ItemEvent pVal)
    {
        try
        {
            switch (pVal.ItemUID)
            {
                case tbeBizCharge:
                    form.PaneLevel = paneBP;
                    break;
                case tbCreditCard:
                    form.PaneLevel = paneCCLog;
                    strWhere = string.Format(" Where CustomerID='{0}' ", getItemValue(form, "5"));
                    populateLog(form);  
                    break;
                case tbPaymentMethod:
                    form.PaneLevel = paneBP;
                    break;
                case "18":
                    loadCustData(form);
                    break;
                case btnAdd:
                    bAuto = false;
                    SAPCust sapcust = new SAPCust();
                    if(!loadFormData(form, ref sapcust, false))
                        return;
                    sapcust.cccust.CustomerID = getFormEditVal(form, "5");
                    sapcust.custObj.CustomerID = getFormEditVal(form, "5");
                    if (Validate(form, sapcust.custObj))
                    {
                        try
                        {
                           
                            if (getComboBoxVal(form, cbActive) == "Y")
                                sapcust.cccust.active = 'Y';
                            else
                                sapcust.cccust.active = 'N';
                            if (AddCustomer(ref sapcust))
                            {
                                SBO_Application.MessageBox("Credit card added.");
                                reload(form, getLabelCaption(form, stRecordID), ref SAPCustList, ref selSAPCust, true);
                            }else
                                SBO_Application.MessageBox("Failed to added credit card.");
                        }
                        catch (Exception ex)
                        {
                            SBO_Application.MessageBox("Failed to add your card: " + ex.Message);
                        }
                        
                    }
                    break;
                case btnDelete:
                    bAuto = false;
                    if (selSAPCust == null)
                    {                        
                        SBO_Application.MessageBox("Please select a credit card.");
                    }
                    else
                    {
                        bAuto = false;
                        if (SBO_Application.MessageBox("Are you sure you want to remove credit card " + selSAPCust.key + "?", 1, "Yes", "No") == 1)
                        {
                            deleteCustomer(selSAPCust.custObj.CustNum);
                            db.CCCUSTs.DeleteOnSubmit(selSAPCust.cccust);
                            db.SubmitChanges();
                            reload(form, getLabelCaption(form, stRecordID), ref SAPCustList, ref selSAPCust, true);

                            SBO_Application.MessageBox("Credit card removed.");
                        }
                    }
                    break;
                case btnUpdate:
                    {
                        bAuto = false;
                        if (selSAPCust == null)
                        {
                            SBO_Application.MessageBox("Please select a credit card.");
                            return;
                        }
                        if(!loadFormData(form, ref selSAPCust, false))
                            return;
                        if (selSAPCust.custObj.PaymentMethods[0].CardNumber.IndexOf("XXX") != -1 && selSAPCust.custObj.PaymentMethods[0].Account != null)
                        {
                            SBO_Application.MessageBox("Please enter unmasked credit card number.");
                            return;
                        }
                        if (Validate(form, selSAPCust.custObj))
                        {
                            if (updateCustomer(selSAPCust.custObj))
                            {
                                updateCustDeclined(selSAPCust.cccust.recID, "N");
                                selSAPCust.cccust.Declined = 'N';
                                reload(form, getLabelCaption(form, stRecordID), ref SAPCustList, ref selSAPCust, true);
                                SBO_Application.MessageBox("Credit card updated.");
                                
                            }
                            else
                            {
                                SBO_Application.MessageBox("Failed to update credit card.");
                            }
                        }
                    }
                    break;
            }

        }catch(Exception ex)
        {
            errorLog(ex);
        }

    }