Ejemplo n.º 1
0
        public TransactionEntity Create(PaymentEntity payment)
        {
            TransactionEntity transaction = new TransactionEntity();
            bool processingError          = false;

            _DownPayment   = Company.GetBusinessObject(BoObjectTypes.oVendorPayments);
            _PaymentEntity = payment;
            _CreatePaymentHeading();
            _AssignPaymentType();

            foreach (var document in payment.Documents)
            {
                TransactionEntity payTransaction        = null;
                TransactionEntity creditNoteTransaction = null;

                if (document.PayAmount > 0)
                {
                    payTransaction = _PayDocument(payment, document);
                    if (!payTransaction.Success)
                    {
                        transaction.Message = payTransaction.Message;
                        processingError     = true;
                        break;
                    }
                }

                if (document.CreditNote.Amount > 0)
                {
                    creditNoteTransaction = _AddCreditNote(payment, document);
                    if (!creditNoteTransaction.Success)
                    {
                        transaction.Message = creditNoteTransaction.Message;
                        processingError     = true;
                        break;
                    }
                }
            }

            if (!processingError)
            {
                if (_DownPayment.Add() != 0)
                {
                    transaction.Message = ErrorMessage;
                }
                else
                {
                    string newEntityId;
                    Company.GetNewObjectCode(out newEntityId);
                    transaction.Successfull(newEntityId);
                }
            }
            else
            {
                _DownPayment.Cancel();
            }

            Company.Disconnect();

            return(transaction);
        }
Ejemplo n.º 2
0
        void IArmada_Sync.Add(string sKey, SAPbobsCOM.Company oCompany, string strLogger, string strWareHouse, string[] strValues, Hashtable htCCdet)
        {
            //Singleton.traceService("Has Record2");
            DataTable oHeader   = null;
            DataTable oDetails  = null;
            DataTable oPayments = null;

            SAPbobsCOM.Documents oInvoiceR = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(BoObjectTypes.oCreditNotes);
            SAPbobsCOM.Payments  oPayment  = (SAPbobsCOM.Payments)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oVendorPayments);

            try
            {
                string str_S_ORIN = "Exec Armada_Service_S_ORIN_s '" + sKey + "'";
                oDataSet = Singleton.objSqlDataAccess.ExecuteDataSet(str_S_ORIN, strLogger);

                if (oDataSet == null && oDataSet.Tables.Count == 0)
                {
                    return;
                }
                else
                {
                    oHeader   = oDataSet.Tables[0];
                    oDetails  = oDataSet.Tables[1];
                    oPayments = oDataSet.Tables[2];

                    if (oHeader != null && oHeader.Rows.Count > 0)
                    {
                        //Singleton.traceService("Has Record");
                        oInvoiceR.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items;

                        //Header Table
                        oInvoiceR.CardCode    = oHeader.Rows[0]["Code"].ToString();
                        oInvoiceR.CardName    = oHeader.Rows[0]["Name"].ToString();
                        oInvoiceR.DocDate     = Convert.ToDateTime(oHeader.Rows[0]["DocDate"].ToString());
                        oInvoiceR.NumAtCard   = oHeader.Rows[0]["DocNum"].ToString();
                        oInvoiceR.DocCurrency = oHeader.Rows[0]["DocCur"].ToString();

                        //oInvoice.DocRate = Convert.ToDouble(oHeader.Rows[0]["DocRate"].ToString());
                        oInvoiceR.Comments = oHeader.Rows[0]["Remarks"].ToString();
                        oInvoiceR.UserFields.Fields.Item("U_Z_PAYTYPE").Value = oHeader.Rows[0]["DocType"].ToString();
                        oInvoiceR.UserFields.Fields.Item("U_Z_CASHIER").Value = oHeader.Rows[0]["Cashier"].ToString();
                        oInvoiceR.UserFields.Fields.Item("U_Z_DOCTIME").Value = oHeader.Rows[0]["DocTime"].ToString();
                        oInvoiceR.UserFields.Fields.Item("U_Z_TrnNum").Value  = oHeader.Rows[0]["DocNum"].ToString();

                        if (oDetails.Rows.Count > 0)
                        {
                            foreach (DataRow dr in oDetails.Rows)
                            {
                                oInvoiceR.Lines.ItemCode        = dr["ItemCode"].ToString();
                                oInvoiceR.Lines.ItemDescription = dr["ItemDesc"].ToString();
                                oInvoiceR.Lines.Quantity        = Convert.ToDouble(dr["Qty"].ToString());
                                oInvoiceR.Lines.UnitPrice       = Convert.ToDouble(dr["UnitPrice"].ToString());
                                //oInvoice.Lines.Currency = dr["Currency"].ToString();
                                oInvoiceR.Lines.WarehouseCode = strWareHouse;
                                if (strValues[1] != "")
                                {
                                    oInvoiceR.Lines.CostingCode = strValues[1];
                                }
                                oInvoiceR.Lines.Add();
                            }
                        }
                        //oInvoice.DocTotal = Convert.ToDouble(oHeader.Rows[0]["DocTotal"].ToString());

                        if (oCompany.InTransaction)
                        {
                            oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                        }

                        oCompany.StartTransaction();

                        int intError = oInvoiceR.Add();
                        if (intError != 0)
                        {
                            //Singleton.traceService(intError.ToString());
                            Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARCreditMemo.ToString(), "0", "0", 0, intError.ToString(), oCompany.GetLastErrorDescription().Replace("'", ""), strLogger);
                            if (oCompany.InTransaction)
                            {
                                oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                        }
                        else
                        {
                            //Singleton.traceService("Success");
                            string strDkey;
                            int    intDocNum = 0;
                            oCompany.GetNewObjectCode(out strDkey);
                            if (oInvoiceR.GetByKey(Convert.ToInt32(strDkey)))
                            {
                                intDocNum = oInvoiceR.DocNum;
                            }

                            //Singleton.traceService("Success2");

                            oPayment.CardCode    = oHeader.Rows[0]["Code"].ToString();
                            oPayment.DocType     = SAPbobsCOM.BoRcptTypes.rCustomer;
                            oPayment.DocDate     = Convert.ToDateTime(oHeader.Rows[0]["DocDate"].ToString());
                            oPayment.TaxDate     = Convert.ToDateTime(oHeader.Rows[0]["DocDate"].ToString());
                            oPayment.DocCurrency = oHeader.Rows[0]["DocCur"].ToString();
                            //Singleton.traceService("Success3");

                            oPayment.Invoices.DocEntry    = Convert.ToInt32(strDkey);
                            oPayment.Invoices.InvoiceType = SAPbobsCOM.BoRcptInvTypes.it_CredItnote;
                            oPayment.Invoices.SumApplied  = Convert.ToDouble(oHeader.Rows[0]["InvTotal"].ToString());
                            oPayment.Invoices.Add();

                            //Singleton.traceService("Success4");

                            if (oPayments.Rows.Count > 0)
                            {
                                foreach (DataRow dr in oPayments.Rows)
                                {
                                    //if (dr["PayMethod"].ToString() == "R")
                                    //{
                                    //    oPayment.CreditCards.CreditCard = 1;
                                    //    oPayment.CreditCards.CreditCardNumber = "1111";
                                    //    oPayment.CreditCards.CardValidUntil = System.DateTime.Now;
                                    //    oPayment.CreditCards.PaymentMethodCode = 1;
                                    //    oPayment.CreditCards.CreditSum = Convert.ToDouble(dr["PayAmount"].ToString());
                                    //    oPayment.CreditCards.VoucherNum = "1111";
                                    //    oPayment.CreditCards.Add();
                                    //    Singleton.traceService("Payment Credit");
                                    //}
                                    //else
                                    {
                                        oPayment.CashAccount = strValues[0].ToString();
                                        oPayment.CashSum     = Convert.ToDouble(dr["PayAmount"].ToString());
                                        //Singleton.traceService("Payment Cash");
                                    }
                                }
                            }

                            //Singleton.traceService("Payment Adding");
                            try
                            {
                                int intPayment = oPayment.Add();
                                if (intPayment == 0)
                                {
                                    //Singleton.traceService("Payment Successs");
                                    if (oCompany.InTransaction)
                                    {
                                        oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                                    }
                                    Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARCreditMemo.ToString(), strDkey, intDocNum.ToString(), 1, "", "Armada_Sync Completed Sucessfully", strLogger);
                                }
                                else
                                {
                                    //Singleton.traceService(intPayment.ToString());
                                    Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARCreditMemo.ToString(), "0", "0", 0, intPayment.ToString(), oCompany.GetLastErrorDescription().Replace("'", ""), strLogger);
                                    if (oCompany.InTransaction)
                                    {
                                        oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                if (oCompany.InTransaction)
                                {
                                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                }
                                Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARCreditMemo.ToString(), "0", "0", 0, "0", ex.Message.ToString(), strLogger);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARCreditMemo.ToString(), "0", "0", 0, "0", ex.Message.ToString(), strLogger);
                if (oCompany.InTransaction)
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                }
                throw ex;
            }
            finally
            {
                oHeader  = null;
                oDetails = null;
                oDataSet = null;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oInvoiceR);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oPayment);
            }
        }
Ejemplo n.º 3
0
        void IArmada_Sync.Add(string sKey, SAPbobsCOM.Company oCompany, string strLogger, string strWareHouse, string[] strValues, Hashtable htCCdet)
        {
            DataTable oHeader   = null;
            DataTable oDetails  = null;
            DataTable oPayments = null;

            SAPbobsCOM.Documents oInvoice = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(BoObjectTypes.oInvoices);
            SAPbobsCOM.Payments  oPayment = (SAPbobsCOM.Payments)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments);

            try
            {
                string str_S_OINV = "Exec Armada_Service_S_OINV_s '" + sKey + "'";
                traceService("Query :" + str_S_OINV);
                oDataSet = Singleton.objSqlDataAccess.ExecuteDataSet(str_S_OINV, strLogger);

                if (oDataSet == null && oDataSet.Tables.Count == 0)
                {
                    return;
                }
                else
                {
                    oHeader   = oDataSet.Tables[0];
                    oDetails  = oDataSet.Tables[1];
                    oPayments = oDataSet.Tables[2];
                    traceService("Adding HASRCROD");

                    if (oHeader != null && oHeader.Rows.Count > 0)
                    {
                        traceService("Adding INvoice");
                        oInvoice.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items;

                        //Header Table
                        oInvoice.CardCode    = oHeader.Rows[0]["Code"].ToString();
                        oInvoice.CardName    = oHeader.Rows[0]["Name"].ToString();
                        oInvoice.DocDate     = Convert.ToDateTime(oHeader.Rows[0]["DocDate"].ToString());
                        oInvoice.NumAtCard   = oHeader.Rows[0]["DocNum"].ToString();
                        oInvoice.DocCurrency = oHeader.Rows[0]["DocCur"].ToString();
                        //oInvoice.DocRate = Convert.ToDouble(oHeader.Rows[0]["DocRate"].ToString());
                        oInvoice.Comments        = oHeader.Rows[0]["Remarks"].ToString();
                        oInvoice.DiscountPercent = Convert.ToDouble(oHeader.Rows[0]["DisPrct"].ToString());
                        oInvoice.UserFields.Fields.Item("U_Z_PAYTYPE").Value = oHeader.Rows[0]["DocType"].ToString();
                        oInvoice.UserFields.Fields.Item("U_Z_CASHIER").Value = oHeader.Rows[0]["Cashier"].ToString();
                        oInvoice.UserFields.Fields.Item("U_Z_DOCTIME").Value = oHeader.Rows[0]["DocTime"].ToString();
                        oInvoice.UserFields.Fields.Item("U_Z_TrnNum").Value  = oHeader.Rows[0]["DocNum"].ToString();

                        if (oDetails.Rows.Count > 0)
                        {
                            traceService("Adding Details");
                            foreach (DataRow dr in oDetails.Rows)
                            {
                                oInvoice.Lines.ItemCode        = dr["ItemCode"].ToString();
                                oInvoice.Lines.ItemDescription = dr["ItemDesc"].ToString();
                                oInvoice.Lines.Quantity        = Convert.ToDouble(dr["Qty"].ToString());
                                oInvoice.Lines.UnitPrice       = Convert.ToDouble(dr["UnitPrice"].ToString());
                                //oInvoice.Lines.Currency = dr["Currency"].ToString();
                                oInvoice.Lines.WarehouseCode = strWareHouse;
                                if (strValues[0] != "")
                                {
                                    oInvoice.Lines.CostingCode = strValues[0];
                                }
                                oInvoice.Lines.Add();
                            }
                            traceService("Details Added");
                        }
                        //oInvoice.DocTotal = Convert.ToDouble(oHeader.Rows[0]["DocTotal"].ToString());

                        if (oCompany.InTransaction)
                        {
                            oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                        }


                        oCompany.StartTransaction();

                        int intError = oInvoice.Add();
                        if (intError != 0)
                        {
                            traceService(oCompany.GetLastErrorDescription());

                            if (oCompany.InTransaction)
                            {
                                oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }

                            Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARInvoice.ToString(), "0", "0", 0, oCompany.GetLastErrorCode().ToString(), oCompany.GetLastErrorDescription().Replace("'", ""), strLogger);
                        }
                        else
                        {
                            string strDkey;
                            int    intDocNum = 0;
                            oCompany.GetNewObjectCode(out strDkey);

                            if (oInvoice.GetByKey(Convert.ToInt32(strDkey)))
                            {
                                intDocNum = oInvoice.DocNum;
                            }

                            if (oHeader.Rows[0]["DocType"].ToString() == "P")
                            {
                                oPayment.CardCode    = oHeader.Rows[0]["Code"].ToString();
                                oPayment.DocType     = SAPbobsCOM.BoRcptTypes.rCustomer;
                                oPayment.DocDate     = Convert.ToDateTime(oHeader.Rows[0]["DocDate"].ToString());
                                oPayment.TaxDate     = Convert.ToDateTime(oHeader.Rows[0]["DocDate"].ToString());
                                oPayment.DocCurrency = oHeader.Rows[0]["DocCur"].ToString();

                                oPayment.Invoices.DocEntry    = Convert.ToInt32(strDkey);
                                oPayment.Invoices.InvoiceType = SAPbobsCOM.BoRcptInvTypes.it_Invoice;
                                oPayment.Invoices.SumApplied  = Convert.ToDouble(oHeader.Rows[0]["InvTotal"].ToString());
                                oPayment.Invoices.Add();

                                if (oPayments.Rows.Count > 0)
                                {
                                    foreach (DataRow dr in oPayments.Rows)
                                    {
                                        if (dr["PayMethod"].ToString() == "R")
                                        {
                                            DataRow ccRows = (DataRow)htCCdet[dr["CardType"].ToString()];
                                            if (ccRows != null)
                                            {
                                                oPayment.CreditCards.CreditCard        = Convert.ToInt16(ccRows["U_CREDITCARD"].ToString());
                                                oPayment.CreditCards.CreditCardNumber  = (ccRows["U_CARDNUMBER"].ToString());
                                                oPayment.CreditCards.CardValidUntil    = Convert.ToDateTime(ccRows["U_CARDVALID"].ToString());
                                                oPayment.CreditCards.PaymentMethodCode = Convert.ToInt16(ccRows["U_PAYMENTMETHOD"].ToString());
                                                oPayment.CreditCards.CreditSum         = Convert.ToDouble(dr["PayAmount"].ToString());
                                                oPayment.CreditCards.VoucherNum        = "1111";
                                                oPayment.CreditCards.Add();
                                            }
                                        }
                                        else
                                        {
                                            oPayment.CashSum = Convert.ToDouble(dr["PayAmount"].ToString());
                                        }
                                    }
                                }

                                int intPayment = oPayment.Add();
                                if (intPayment == 0)
                                {
                                    if (oCompany.InTransaction)
                                    {
                                        oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                                    }

                                    traceService("Commited");
                                    Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARInvoice.ToString(), strDkey, intDocNum.ToString(), 1, "", "Armada_Sync Completed Sucessfully", strLogger);
                                    traceService("Commited Completed..");
                                }
                                else
                                {
                                    Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARInvoice.ToString(), "0", "0", 0, oCompany.GetLastErrorCode().ToString(), oCompany.GetLastErrorDescription().Replace("'", ""), strLogger);
                                    if (oCompany.InTransaction)
                                    {
                                        oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                }
                            }
                            else
                            {
                                if (oCompany.InTransaction)
                                {
                                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                                }

                                traceService("Commited1");
                                Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARInvoice.ToString(), strDkey, intDocNum.ToString(), 1, "", "Armada_Sync Completed Sucessfully", strLogger);
                                traceService("Commited Completed..1");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Singleton.objSqlDataAccess.UpdateLog(sKey, TransScenerio.ARInvoice.ToString(), "0", "0", 0, "0", ex.Message.ToString(), strLogger);
                if (oCompany.InTransaction)
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                }
                traceService("Error 1 : " + ex.Message);
                throw ex;
            }
            finally
            {
                oHeader  = null;
                oDetails = null;
                oDataSet = null;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oInvoice);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oPayment);
            }
        }