Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Create Draft Payment linked to invoice (DI API) (C#)

0 Likes
1,236
  • SAP Managed Tags

Hi, I need to create draft payments using DI API, I can do it in "PayNoDoc" and "Account" payments. But I can't link Payment to partner's invoice(s). Here is my code:

private void CreateDraftPaymentAcc()
        {
            if (CheckIfValidDraftData())
            {
                //https://answers.sap.com/questions/11145336/creacion-de-documento-preliminar-sdk.html
                //Mandatory fields in SAP Business One: CardCode, CashSum, TransferAccount, and TransferSum.

                Int32 lRetCode, temp, nErr;
                String strDocEntry, errMsg;

                SAPbobsCOM.Payments DraftPayment = oCompany.GetBusinessObject(BoObjectTypes.oPaymentsDrafts);

                // Common Data
                DraftPayment.DocObjectCode = (fldPaymentType.SelectedIndex == IncomingPayments) ?
                    BoPaymentsObjectType.bopot_IncomingPayments : BoPaymentsObjectType.bopot_OutgoingPayments;

                if (fldDocType.SelectedIndex == NormalPayment || fldDocType.SelectedIndex == NormalAdvance)
                    DraftPayment.DocType = (fldPaymentType.SelectedIndex == IncomingPayments) ? BoRcptTypes.rCustomer : BoRcptTypes.rSupplier;
                else if (fldDocType.SelectedIndex == AccountPayment)
                    DraftPayment.DocType = BoRcptTypes.rAccount;
                else if (fldDocType.SelectedIndex == RefundPayment)
                    DraftPayment.DocType = (fldPaymentType.SelectedIndex == IncomingPayments) ? BoRcptTypes.rSupplier : BoRcptTypes.rCustomer;
                DraftPayment.TransferDate = Convert.ToDateTime(fldTaxDate.Text); // Fecha de Transferencia
                DraftPayment.TaxDate = Convert.ToDateTime(fldTaxDate.Text); // Fecha de Documento
                DraftPayment.DocDate = Convert.ToDateTime(fldDocDate.Text);  // Fecha de Contabilización
                DraftPayment.TransferReference = fldTransferReference.Text;
                DraftPayment.TransferSum = Convert.ToDouble(fldTransferSum.Text);
                DraftPayment.TransferAccount = fldTransferAccount.SelectedValue.ToString();
                DraftPayment.Remarks = fldComments.Text;
                DraftPayment.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO;

                // NormalPayment
                if (fldDocType.SelectedIndex == NormalPayment)
                {
                    DraftPayment.Invoices.Add();
                    DraftPayment.Invoices.DocEntry = 1038; // Hardcoded test!
                }// NormalAdvance
                if (fldDocType.SelectedIndex == NormalAdvance)
                {
                    DraftPayment.ControlAccount = (fldPaymentType.SelectedIndex == IncomingPayments) ? 
                        NormalAdvanceAccountCustomers : NormalAdvanceAccountSuppliers;
                }
                // AccountPayment
                if (fldDocType.SelectedIndex == AccountPayment)
                {
                    DraftPayment.AccountPayments.AccountCode = fldControlAccount.SelectedValue.ToString();
                    DraftPayment.AccountPayments.SumPaid = Convert.ToDouble(fldTransferSum.Text);
                    DraftPayment.AccountPayments.Decription = fldDecription.Text; // Info detallada / Comentarios documento
                    DraftPayment.CardName = fldCardName.Text;
                }
                else
                {
                    DraftPayment.CardCode = fldCardCode.SelectedValue.ToString();
                }
                // OutgoingPayments IGTF (Only)
                if (fldPaymentType.SelectedIndex == OutgoingPayments)
                {
                    DraftPayment.UserFields.Fields.Item("U_CTS_ImptGTF").Value = (fldU_CTS_ImptGTF.Checked) ? "Y" : "N";
                }

                lRetCode = DraftPayment.Add();

                oCompany.GetLastError(out nErr, out errMsg);
                if (nErr != 0)
                    ShowError("Found error:" + nErr + ", " + errMsg);
                else
                {
                    oCompany.GetNewObjectCode(out strDocEntry);
                    temp = Convert.ToInt32(strDocEntry);
                    ShowMsg("Documento fue creado con el número de documento preliminar " +
                            strDocEntry.ToString());
                }
            }
        }

How I can find and link partner's invoices to payment?

Hi, I need to create draft payments using DI API, I can do it in "PayNoDoc" and "Account" payments. But I can't link Payment to partner's invoice(s). Here is my code:

private void CreateDraftPaymentAcc()
        {
            if (CheckIfValidDraftData())
            {
                //https://answers.sap.com/questions/11145336/creacion-de-documento-preliminar-sdk.html
                //Mandatory fields in SAP Business One: CardCode, CashSum, TransferAccount, and TransferSum.

                Int32 lRetCode, temp, nErr;
                String strDocEntry, errMsg;

                SAPbobsCOM.Payments DraftPayment = oCompany.GetBusinessObject(BoObjectTypes.oPaymentsDrafts);

                // Common Data
                DraftPayment.DocObjectCode = (fldPaymentType.SelectedIndex == IncomingPayments) ?
                    BoPaymentsObjectType.bopot_IncomingPayments : BoPaymentsObjectType.bopot_OutgoingPayments;

                if (fldDocType.SelectedIndex == NormalPayment || fldDocType.SelectedIndex == NormalAdvance)
                    DraftPayment.DocType = (fldPaymentType.SelectedIndex == IncomingPayments) ? BoRcptTypes.rCustomer : BoRcptTypes.rSupplier;
                else if (fldDocType.SelectedIndex == AccountPayment)
                    DraftPayment.DocType = BoRcptTypes.rAccount;
                else if (fldDocType.SelectedIndex == RefundPayment)
                    DraftPayment.DocType = (fldPaymentType.SelectedIndex == IncomingPayments) ? BoRcptTypes.rSupplier : BoRcptTypes.rCustomer;
                DraftPayment.TransferDate = Convert.ToDateTime(fldTaxDate.Text); // Fecha de Transferencia
                DraftPayment.TaxDate = Convert.ToDateTime(fldTaxDate.Text); // Fecha de Documento
                DraftPayment.DocDate = Convert.ToDateTime(fldDocDate.Text);  // Fecha de Contabilización
                DraftPayment.TransferReference = fldTransferReference.Text;
                DraftPayment.TransferSum = Convert.ToDouble(fldTransferSum.Text);
                DraftPayment.TransferAccount = fldTransferAccount.SelectedValue.ToString();
                DraftPayment.Remarks = fldComments.Text;
                DraftPayment.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO;

                // NormalPayment
                if (fldDocType.SelectedIndex == NormalPayment)
                {
                    DraftPayment.Invoices.Add();
                    DraftPayment.Invoices.DocEntry = 1038; // Hardcoded test!
                }// NormalAdvance
                if (fldDocType.SelectedIndex == NormalAdvance)
                {
                    DraftPayment.ControlAccount = (fldPaymentType.SelectedIndex == IncomingPayments) ? 
                        NormalAdvanceAccountCustomers : NormalAdvanceAccountSuppliers;
                }
                // AccountPayment
                if (fldDocType.SelectedIndex == AccountPayment)
                {
                    DraftPayment.AccountPayments.AccountCode = fldControlAccount.SelectedValue.ToString();
                    DraftPayment.AccountPayments.SumPaid = Convert.ToDouble(fldTransferSum.Text);
                    DraftPayment.AccountPayments.Decription = fldDecription.Text; // Info detallada / Comentarios documento
                    DraftPayment.CardName = fldCardName.Text;
                }
                else
                {
                    DraftPayment.CardCode = fldCardCode.SelectedValue.ToString();
                }
                // OutgoingPayments IGTF (Only)
                if (fldPaymentType.SelectedIndex == OutgoingPayments)
                {
                    DraftPayment.UserFields.Fields.Item("U_CTS_ImptGTF").Value = (fldU_CTS_ImptGTF.Checked) ? "Y" : "N";
                }

                lRetCode = DraftPayment.Add();

                oCompany.GetLastError(out nErr, out errMsg);
                if (nErr != 0)
                    ShowError("Found error:" + nErr + ", " + errMsg);
                else
                {
                    oCompany.GetNewObjectCode(out strDocEntry);
                    temp = Convert.ToInt32(strDocEntry);
                    ShowMsg("Documento fue creado con el número de documento preliminar " +
                            strDocEntry.ToString());
                }
            }
        }

How I can find and link partner's invoices to payment?

0 REPLIES 0