Exemplo n.º 1
0
        private void postAllocationJERev(int jeEntry, int lineNum, int CnEntry)
        {
            try
            {
                SAPbobsCOM.JournalEntries apJE = (SAPbobsCOM.JournalEntries)oCompany.GetBusinessObject(BoObjectTypes.oJournalEntries);
                apJE.GetByKey(jeEntry);

                if (apJE.Cancel() != 0)
                {
                    int    erroCode = 0;
                    string errDescr = "";
                    Program.objHrmsUI.oCompany.GetLastError(out erroCode, out errDescr);
                    oApplication.StatusBar.SetText("Failed to cancel JE  : " + errDescr);
                }
                else
                {
                    string outStr = Convert.ToString(Program.objHrmsUI.oCompany.GetNewObjectKey());


                    string updateCall = "UPDATE RPC1 set \"U_AlocJeRev\"='" + outStr + "' WHERE \"DocEntry\" = '" + CnEntry.ToString() + "' AND \"LineNum\"='" + lineNum.ToString() + "'";
                    int    result     = Program.objHrmsUI.ExecQuery(updateCall, "Update Line JE");

                    oApplication.Menus.Item("1304").Activate();
                }
            }
            catch (Exception ex)
            {
                oApplication.MessageBox(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void addChildJeLines(SAPbobsCOM.JournalEntries AllocationJE, string AMCode, double devideAmount, string debitAccount, string AllocBs, string FA, string costCode, string AllocationRate)
        {
//            string strAMChildern = @"
//                                        select case convert(varchar, '~p1') when '01' then u_area when '02' then U_Volume when '03' then U_Floors else U_Area end as AllocValue
//                                        , code,name,U_Father,U_AcctCode , isnull(u_facode,'') as FA
//                                         from [@B1_AM] t0 where U_Father = '~p2'";
            Hashtable hp = new Hashtable();

            hp.Clear();
            hp.Add("~p1", AllocBs);
            hp.Add("~p2", AMCode);

            string strAMChildern = Program.objHrmsUI.getQryString("141_GET_003", hp);// "Update pch1 set U_AlocJE='~p1' where docentry = '~p2' and linenum='~p3'";

            System.Data.DataTable dtChildrens = Program.objHrmsUI.getDataTable(strAMChildern, "Getting Childeren");
            if (dtChildrens.Rows.Count == 0)
            {
                AllocationJE.Lines.AccountCode = debitAccount;
                AllocationJE.Lines.Debit       = Convert.ToDouble(Convert.ToInt32(devideAmount * 100)) / 100;
                AllocationJE.Lines.Reference1  = costCode;
                AllocationJE.Lines.Reference2  = FA;
                AllocationJE.Lines.UserFields.Fields.Item("U_B1_APP").Value = AllocationRate;
                AllocationJE.Lines.Add();
            }
            else
            {
                double unitTotal = 0;
                foreach (DataRow drChild in dtChildrens.Rows)
                {
                    unitTotal += Convert.ToDouble(drChild["AllocValue"]);
                }
                foreach (DataRow drChild in dtChildrens.Rows)
                {
                    string childCode    = drChild["code"].ToString();
                    string ChildAccount = drChild["U_AcctCode"].ToString();
                    double ChildVal     = Convert.ToDouble(drChild["AllocValue"]);
                    string cFA          = drChild["FA"].ToString();
                    double debitAmount  = devideAmount * ChildVal / unitTotal;
                    addChildJeLines(AllocationJE, childCode, debitAmount, ChildAccount, AllocBs, cFA, costCode, AllocationRate);
                }
            }
        }
Exemplo n.º 3
0
        private void btnCarga_ClickBefore(object sboObject, SAPbouiCOM.SBOItemEventArg pVal, out bool BubbleEvent)
        {
            BubbleEvent   = true;
            mListObjLogin = new List <LoginDTO>();
            AccountsDAO lObjAccounts  = null;
            string      lStrCtaPuente = "";

            bool lBolResult = Check_txts();

            if (lBolResult && gLstNomina.Count > 0)
            {
                //Tipo de Cambio USD
                if (!CheckCurrencyRate())
                {
                    Application.SBO_Application.StatusBar.SetText("Proceso Cancelado. Actualice el tipo de cambio USD.", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                    return;
                }
                try
                {
                    this.UIAPIRawForm.Freeze(true);
                    mObjJournalEntries = (SAPbobsCOM.JournalEntries)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries);

                    mListObjLogin = GetSetupLogin();
                    LoginDTO lObjLoginDTO = mListObjLogin.FirstOrDefault(x => x.Code == int.Parse(lStrValueCmb));

                    lStrCtaPuente = lObjLoginDTO.AccountingAccount;

                    if (lObjLoginDTO != null)
                    {
                        //Existe Cuentas
                        string lStrResult = string.Empty;
                        string lStrYear   = txtYear.Value;
                        string lStrPeriod = cmbPeriod.Value;
                        string lStrNo     = txtNo.Value;

                        Application.SBO_Application.StatusBar.SetText("Procesando cuentas contables... Porfavor espere", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);

                        lObjAccounts = new AccountsDAO();

                        var lVarGroupAcc = from p in gLstNomina group p by p.CUENTA into grouped select grouped;

                        lStrResult = lObjAccounts.CheckAccounts(lVarGroupAcc);

                        if (lStrResult != string.Empty)
                        {
                            Application.SBO_Application.StatusBar.SetText("Proceso Cancelado. Actualice las cuentas." + lStrResult, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                            return;
                        }

                        Application.SBO_Application.StatusBar.SetText("Procesando centros de costos... Porfavor espere", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);

                        //Existe Centro de Costos
                        lStrResult   = string.Empty;
                        lObjAccounts = new AccountsDAO();

                        var lVarGpCC = from p in gLstNomina group p by p.CUENTA2 into grouped select grouped;

                        lStrResult = lObjAccounts.CheckCostingCode(lVarGpCC);

                        if (lStrResult != string.Empty)
                        {
                            Application.SBO_Application.StatusBar.SetText("Proceso Cancelado. Actualice los Centros de Costo." + lStrResult, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                            return;
                        }

                        mDoubleImpoDedu = 0.0;
                        mDoubleImpoPerc = 0.0;

                        //Obtener Clave de SAP en empleados
                        List <EmployeesDTO> lLstEmployeesDTO = mObjEmployeesDAO.GetEmployeeID();

                        var lObjQuery = from nom in gLstNomina
                                        join emp in lLstEmployeesDTO
                                        on nom.ATRAB equals emp.IdEmpSAP
                                        select new { nom, emp };

                        List <string> lLstMissingEmp = new List <string>();
                        foreach (var lObjQItem in lObjQuery)
                        {
                            if (lObjQItem.emp.IdEmpNomina == null)
                            {
                                lLstMissingEmp.Add(lObjQItem.emp.FullName);
                            }

                            lObjQItem.nom.ATRAB = (int?)lObjQItem.emp.IdEmpNomina;
                        }

                        if (lLstMissingEmp.Count > 0)
                        {
                            string lStrMissingEmp = string.Empty;
                            foreach (var lObjEmpItem in lLstMissingEmp.Distinct().ToList())
                            {
                                lStrMissingEmp += lObjEmpItem + ", ";
                            }

                            Application.SBO_Application.MessageBox("Para continuar, registre en SAP los siguientes empleados: " + lStrMissingEmp);
                            NewSearch();

                            return;
                        }

                        mObjJournalEntries = PopulateJournalEntries();                                       //encabezado
                        mObjJournalEntries = PopulateDetails(mObjJournalEntries, gLstNomina, lStrCtaPuente); //lineas

                        int lIntRespJournal = mObjJournalEntries.Add();
                        if (lIntRespJournal == 0)
                        {
                            NewSearch();
                            Application.SBO_Application.MessageBox("Proceso terminado. Se cargo con exito el asiento contable");
                            Application.SBO_Application.StatusBar.SetText("Proceso terminado. Se cargo con exito el asiento contable", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                        }
                        else
                        {
                            int    lIntError = 0;
                            string lStrError = string.Empty;
                            string xdxd      = DIApplication.Company.GetLastErrorDescription();
                            DIApplication.Company.GetLastError(out lIntError, out lStrError);

                            Application.SBO_Application.StatusBar.SetText("Proceso Cancelado. Error al cargar el asiento contable " + lStrError, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                        }
                    }
                    else
                    {
                        Application.SBO_Application.StatusBar.SetText("No se puedo establecer la conexión con el Servidor de Nómina", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
                    }
                }
                catch (Exception ex)
                {
                    Application.SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                }
                finally
                {
                    this.UIAPIRawForm.Freeze(false);
                    MemoryUtility.ReleaseComObject(mObjJournalEntries);

                    //btnCarga.Item.Enabled = false;
                }
            }
            else
            {
                Application.SBO_Application.StatusBar.SetText("No hay datos a importar. Favor de primero Buscar Nómina", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Funcion utilizada para mandar a SAP la información del diario contable
        /// </summary>
        /// <returns></returns>
        public string funEnviarDiarioSAP()
        {
            try {
                string mError = "";
                int    iError = 0;
                //Realizamos la conexion a SAP
                csAccesoDatos.proIniciarSesionSAP();
                //Verificamos si el documento ya se encuentra en SAP
                DataTable dtDiarioSAP = funVerificarDiarioSAP(DocNombre, CabNumero);
                //Si el documento se encuentra en SAP actualizamos la información de este en la informacion del animal
                if (dtDiarioSAP.Rows.Count > 0)
                {
                    //Recuperamos en las variables los valores de SAP
                    CabDocEntrySAPDiario = int.Parse(dtDiarioSAP.Rows[0]["TransId"].ToString());
                    CabNumeroSAPDiario   = int.Parse(dtDiarioSAP.Rows[0]["Number"].ToString());
                    //Actualizamos en el movimiento los datos de SAP
                    proActDiario(CabDocEntrySAPDiario, CabNumeroSAPDiario, CabCodigo);
                    //Actualizamos  las lineas del detalle de actualizacion de costos
                    clsGraCstAcumulado.proActualizarCstAcumulado(AnmCodigo, CabFecha, "Bla", "GRA_DETLABORATORIO", "LABORATORIO", CabCodigo);
                    //Actualizamos  las lineas del detalle de actualizacion de costos standares
                    clsGraCstStdAcumulado.proActualizarCstStdAcumulado(AnmCodigo, CabFecha, "Bla", CabCodigo);
                    return(mError);
                }
                else
                {
                    //Variable utilizadas para las cuentas contables parametrizadas
                    string varCodCtaContableWip        = clsGenOpciones.CargarValor("G.Lab.Diario.CtaWip");        //Recuperamos el codigo de la cuenta contable para el costo inicial
                    string varCodCtaContableCstInicial = clsGenOpciones.CargarValor("G.Lab.Diario.CtaCstInicial"); //Recuperamos el codigo de la cuenta contable WIP
                    //Instanciamos en la variable varOJDT el objeto de SAP de diarios contables
                    SAPbobsCOM.JournalEntries varOJDT = csConexionSap.objConexionSap.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries);

                    //Cargamos informacion de la cabecera del diario contable
                    varOJDT.Series        = clsSegDocumento.funRecNumSerieSAPDiario(DocCodigo);
                    varOJDT.ReferenceDate = CabFecha;
                    varOJDT.DueDate       = CabFecha;
                    varOJDT.TaxDate       = CabFecha;
                    varOJDT.Memo          = string.Format("Diario de laboratorio: {0}-{1} {2}", DocNombre, CabNumero, CabComenDiario);
                    varOJDT.Reference3    = DocNombre + "-" + CabNumero;
                    varOJDT.UserFields.Fields.Item("U_Ita_sysusuario").Value   = clsVariablesGlobales.varCodUsuario;
                    varOJDT.UserFields.Fields.Item("U_Ita_sysfecha").Value     = DateTime.Now.ToString("dd/MM/yyyy HH:mm");
                    varOJDT.UserFields.Fields.Item("U_Ita_sysip").Value        = clsVariablesGlobales.varIpMaquina;
                    varOJDT.UserFields.Fields.Item("U_Ita_sysdocumento").Value = DocNombre;
                    varOJDT.UserFields.Fields.Item("U_Ita_sysnumero").Value    = CabNumero.ToString();

                    //Cargamos informacion de los detalles del diario contable
                    decimal varCstTotal = 0;
                    int     i           = 0;
                    //Recuperamos la informacion del costo inicial
                    varOJDT.Lines.SetCurrentLine(i);
                    varOJDT.Lines.AccountCode    = varCodCtaContableCstInicial;
                    varOJDT.Lines.Debit          = 0;
                    varOJDT.Lines.Credit         = double.Parse(CabCstInicial.ToString());
                    varOJDT.Lines.LineMemo       = string.Format("Diario de laboratorio: {0}-{1} {2}", DocNombre, CabNumero, CabComenDiario);
                    varOJDT.Lines.Reference1     = "DEPRECIACION";
                    varOJDT.Lines.Reference2     = "";
                    varOJDT.Lines.ReferenceDate2 = CabFecha;
                    varOJDT.Lines.TaxDate        = CabFecha;
                    varOJDT.Lines.DueDate        = CabFecha;
                    varCstTotal += CabCstInicial;
                    i++;
                    //Recuperamos la informacion del costo acumulado
                    foreach (DataRow drFilaDetalle in clsGraCstAcumulado.funRecTableCstAcumulado(AnmCodigo, CabFecha, "Bla").Rows)
                    {
                        varOJDT.Lines.Add();
                        varOJDT.Lines.SetCurrentLine(i);
                        varOJDT.Lines.AccountCode    = drFilaDetalle["CsaCtaCodigo"].ToString();
                        varOJDT.Lines.Debit          = 0;
                        varOJDT.Lines.Credit         = double.Parse(drFilaDetalle["CsaValor"].ToString());
                        varOJDT.Lines.LineMemo       = string.Format("Diario de laboratorio: {0}-{1} {2}", DocNombre, CabNumero, CabComenDiario);
                        varOJDT.Lines.Reference1     = drFilaDetalle["CsaTipoSalida"].ToString();
                        varOJDT.Lines.Reference2     = "";
                        varOJDT.Lines.ReferenceDate2 = CabFecha;
                        varOJDT.Lines.TaxDate        = CabFecha;
                        varOJDT.Lines.DueDate        = CabFecha;
                        varCstTotal += decimal.Parse(drFilaDetalle["CsaValor"].ToString());
                        i++;
                    }
                    //Recuperamos la informacion del costo standar acumulado
                    foreach (DataRow drFilaDetalle in clsGraCstStdAcumulado.funRecTableCstStdAcumulado(AnmCodigo, CabFecha, "Bla").Rows)
                    {
                        varOJDT.Lines.Add();
                        varOJDT.Lines.SetCurrentLine(i);
                        varOJDT.Lines.AccountCode    = drFilaDetalle["CdaCtaContableSalida"].ToString();
                        varOJDT.Lines.Debit          = 0;
                        varOJDT.Lines.Credit         = double.Parse(drFilaDetalle["CdaValor"].ToString());
                        varOJDT.Lines.LineMemo       = string.Format("Diario de laboratorio: {0}-{1} {2}", DocNombre, CabNumero, CabComenDiario);
                        varOJDT.Lines.Reference1     = drFilaDetalle["CdaDetComentario"].ToString();
                        varOJDT.Lines.Reference2     = "";
                        varOJDT.Lines.ReferenceDate2 = CabFecha;
                        varOJDT.Lines.TaxDate        = CabFecha;
                        varOJDT.Lines.DueDate        = CabFecha;
                        varCstTotal += decimal.Parse(drFilaDetalle["CdaValor"].ToString());
                        i++;
                    }
                    //Informacion del haber
                    varOJDT.Lines.Add();
                    varOJDT.Lines.SetCurrentLine(i);
                    varOJDT.Lines.AccountCode    = varCodCtaContableWip;
                    varOJDT.Lines.Debit          = double.Parse(varCstTotal.ToString());
                    varOJDT.Lines.Credit         = 0;
                    varOJDT.Lines.LineMemo       = string.Format("Diario de laboratorio: {0}-{1} {2}", DocNombre, CabNumero, CabComenDiario);
                    varOJDT.Lines.Reference1     = "";
                    varOJDT.Lines.Reference2     = "";
                    varOJDT.Lines.ReferenceDate2 = CabFecha;
                    varOJDT.Lines.TaxDate        = CabFecha;
                    varOJDT.Lines.DueDate        = CabFecha;

                    iError = varOJDT.Add();
                    if (!iError.Equals(0))
                    {
                        csConexionSap.objConexionSap.GetLastError(out iError, out mError);
                        return(mError);
                    }
                    else
                    {
                        int varDocEntrySAPDiario = 0;
                        int.TryParse(csConexionSap.objConexionSap.GetNewObjectKey().ToString(), out varDocEntrySAPDiario);
                        varOJDT.GetByKey(varDocEntrySAPDiario);
                        int varDocNumSAPDiario = varOJDT.Number;

                        //Actualizamos la linea del detalle con la informacion de SAP de la salida de mercancias en la tabla de detalle de actualizacion de costos de formulacion
                        proActDiario(varDocEntrySAPDiario, varDocNumSAPDiario, CabCodigo);
                        //Actualizamos  las lineas del detalle de actualizacion de costos
                        clsGraCstAcumulado.proActualizarCstAcumulado(AnmCodigo, CabFecha, "Bla", "GRA_DETLABORATORIO", "LABORATORIO", CabCodigo);
                        //Actualizamos  las lineas del detalle de actualizacion de costos standares
                        clsGraCstStdAcumulado.proActualizarCstStdAcumulado(AnmCodigo, CabFecha, "Bla", CabCodigo);
                        return(mError);
                    }
                }
            }
            catch (Exception e) { throw new Exception(e.Message); }
            finally { csAccesoDatos.proFinalizarSesionSAP(); }
        }
Exemplo n.º 5
0
        public string postJe()
        {
            long   jdtNum  = 0;
            int    errnum  = 0;
            string errDesc = "";
            string outStr  = "";

            if (!chkPost.Checked)
            {
                Program.objHrmsUI.oApplication.SetStatusBarMessage("You need to check the approved box before posting");
                return("Error");
            }
            if (txDN.Value == "")
            {
                Program.objHrmsUI.oApplication.SetStatusBarMessage("Select a transaction to post!");
                return("Error");
            }
            SAPbobsCOM.JournalEntries vJE = (SAPbobsCOM.JournalEntries)Program.objHrmsUI.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries);


            string   Remarks     = txRem.Value.ToString();
            DateTime postingDate = DateTime.ParseExact(txDD.Value, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);



            try
            {
                vJE.ReferenceDate = postingDate;
                vJE.TaxDate       = postingDate;
                vJE.DueDate       = postingDate;
                if (Remarks.Length > 20)
                {
                    vJE.Memo = Remarks.Substring(0, 20); // dgSales[3, i].Value.ToString().Substring(0, 20);
                }
                else
                {
                    vJE.Memo = Remarks;
                }
                vJE.Reference  = txRef1.Value;
                vJE.Reference2 = txRef2.Value;
                //   vJE.TransactionCode = "JP";
                vJE.Reference3 = "JP_" + txDN.Value.ToString();

                for (int i = 0; i < mtDet.RowCount; i++)
                {
                    string codetype = dtDet.GetValue("cType", i);
                    string acctcode = dtDet.GetValue("cCode", i);
                    string acctname = dtDet.GetValue("cName", i);
                    string debit    = Convert.ToString(dtDet.GetValue("cDebit", i));
                    string credit   = Convert.ToString(dtDet.GetValue("cCredit", i));
                    string project  = dtDet.GetValue("cProject", i);
                    string ocr1     = dtDet.GetValue("cOcr1", i);
                    string ocr2     = dtDet.GetValue("cOcr2", i);
                    string ocr3     = dtDet.GetValue("cOcr3", i);
                    string ocr4     = dtDet.GetValue("cOcr4", i);
                    string ocr5     = dtDet.GetValue("cOcr5", i);


                    if (codetype == "GL")
                    {
                        vJE.Lines.AccountCode = acctcode;
                    }
                    else
                    {
                        vJE.Lines.ShortName = acctcode;
                    }
                    vJE.Lines.Credit         = Convert.ToDouble(credit);
                    vJE.Lines.Debit          = Convert.ToDouble(debit);
                    vJE.Lines.DueDate        = postingDate;
                    vJE.Lines.ReferenceDate1 = postingDate;
                    vJE.Lines.TaxDate        = postingDate;
                    vJE.Lines.Reference1     = vJE.Reference;
                    vJE.Lines.Reference2     = vJE.Reference2;
                    vJE.Lines.ProjectCode    = project;
                    vJE.Lines.CostingCode    = ocr1;
                    vJE.Lines.CostingCode2   = ocr2;
                    vJE.Lines.CostingCode3   = ocr3;
                    vJE.Lines.CostingCode4   = ocr4;
                    vJE.Lines.CostingCode5   = ocr5;
                    vJE.Lines.Add();
                }
            }
            catch (Exception ex)
            {
                outStr = ex.Message;
            }
            if (vJE.Add() != 0)
            {
                int    erroCode = 0;
                string errDescr = "";
                Program.objHrmsUI.oCompany.GetLastError(out erroCode, out errDescr);
                outStr = "Error:" + errDescr + outStr;
                Program.objHrmsUI.oApplication.SetStatusBarMessage(outStr);
            }
            else
            {
                outStr = Convert.ToString(Program.objHrmsUI.oCompany.GetNewObjectKey());
                string strObjJe = txDN.Value.ToString();

                string strUpdate = " UPDATE \"@ABGP\" SET \"Status\" ='C' ,  \"U_Ref3\"= '" + outStr + "' WHERE \"DocNum\"='" + strObjJe + "'";

                Program.objHrmsUI.ExecQuery(strUpdate, "Updating after posting");

                Program.objHrmsUI.oApplication.SetStatusBarMessage("Journal Entry Created. JE # " + outStr, BoMessageTime.bmt_Medium, false);
                iniUI();
            }
            return(outStr);
        }
Exemplo n.º 6
0
        public static void exploteJEInformation(int JournalEntryNumber)
        {
            List <string> cmdList = new List <string>();

            SAPbobsCOM.JournalEntries   objJE     = null;
            TransactionDetail           objDetail = null;
            Dictionary <string, string> objBPDict = null;
            string strThirdParty = "";

            try
            {
                objJE = MainObject.Instance.B1Company.GetBusinessObject(BoObjectTypes.oJournalEntries);
                if (objJE.GetByKey(JournalEntryNumber))
                {
                    objBPDict = T1.B1.ReletadParties.Instance.getBPThirdPartyRelation();
                    for (int i = 0; i < objJE.Lines.Count; i++)
                    {
                        objJE.Lines.SetCurrentLine(i);
                        Tuple <string, string, string, string, string> accountLevel = getAccountSegments(objJE.Lines.AccountCode);

                        objDetail = new TransactionDetail();

                        objDetail.Debit           = objJE.Lines.Debit;
                        objDetail.Credit          = objJE.Lines.Credit;
                        objDetail.DIM1            = objJE.Lines.CostingCode;
                        objDetail.DIM2            = objJE.Lines.CostingCode2;
                        objDetail.DIM3            = objJE.Lines.CostingCode3;
                        objDetail.DIM4            = objJE.Lines.CostingCode4;
                        objDetail.DIM5            = objJE.Lines.CostingCode5;
                        objDetail.TransactionCode = objJE.TransactionCode;
                        List <Tuple <DateType, int, int, int> > oTupleDateList = getDates(objJE.Lines.DueDate, objJE.Lines.TaxDate, objJE.Lines.ReferenceDate1);

                        #region ThirdParty Assignment
                        if (!String.IsNullOrEmpty(objJE.Lines.ShortName))
                        {
                            if (objBPDict != null && objBPDict.ContainsKey(objJE.Lines.ShortName))
                            {
                                strThirdParty = objBPDict[objJE.Lines.ShortName];
                            }
                        }

                        try
                        {
                            if (!String.IsNullOrEmpty(objJE.Lines.UserFields.Fields.Item("U_BYB_RELPAR").Value))
                            {
                                strThirdParty = objJE.Lines.UserFields.Fields.Item("U_BYB_RELPAR").Value;
                            }
                        }
                        catch (Exception er)
                        {
                            _Logger.Error("The UDF U_BYB_RELPAR was not found in DB");
                        }
                        #endregion

                        List <string> strResult = buildCommand(objDetail, accountLevel, oTupleDateList);
                        cmdList.AddRange(strResult);
                    }

                    SAPbobsCOM.Recordset objRs = null;
                    foreach (string strCommand in cmdList)
                    {
                        try
                        {
                            objRs = MainObject.Instance.B1Company.GetBusinessObject(BoObjectTypes.BoRecordset);
                            objRs.DoQuery(strCommand);
                        }
                        catch (Exception er)
                        {
                            _Logger.Error("Error while executing command " + strCommand + " for JE " + JournalEntryNumber.ToString(), er);
                        }
                    }
                    string strComm = Settings._BalanceTerceros.upsertObjectControl
                                     .Replace("[--LastTrans--]", JournalEntryNumber.ToString());

                    objRs = MainObject.Instance.B1Company.GetBusinessObject(BoObjectTypes.BoRecordset);
                    objRs.DoQuery(strComm);
                    objRs   = null;
                    cmdList = null;
                }
                else
                {
                    _Logger.Error("Could not retrieve JE number " + JournalEntryNumber);
                }
            }
            catch (Exception er)
            {
                _Logger.Error("", er);
                cmdList = new List <string>();
            }
            finally
            {
                if (objJE != null)
                {
                    objJE = null;
                }
            }
            //return cmdList;
        }
Exemplo n.º 7
0
        private void postAllocationJE(int invEntry)
        {
            try
            {
                SAPbobsCOM.Documents      apInv = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(BoObjectTypes.oPurchaseInvoices);
                SAPbobsCOM.JournalEntries apJE  = (SAPbobsCOM.JournalEntries)oCompany.GetBusinessObject(BoObjectTypes.oJournalEntries);
                SAPbobsCOM.JournalEntries AllocationJE;
                apInv.GetByKey(invEntry);
                int ApJeNum = apInv.TransNum;
                apJE.GetByKey(ApJeNum);

                System.Data.DataTable dtCandidateRows = new System.Data.DataTable();

                dtCandidateRows.Columns.Add("LineNum");
                dtCandidateRows.Columns.Add("AlocCode");
                dtCandidateRows.Columns.Add("GLCode");
                dtCandidateRows.Columns.Add("Amount");
                dtCandidateRows.Columns.Add("DR");


                for (int i = 0; i < apInv.Lines.Count; i++)
                {
                    apInv.Lines.SetCurrentLine(i);
                    if (apInv.Lines.UserFields.Fields.Item("U_CostCode").Value.ToString().Trim() != "" && (apInv.Lines.UserFields.Fields.Item("U_AlocJe").Value.ToString().Trim() == "0" || apInv.Lines.UserFields.Fields.Item("U_AlocJe").Value.ToString().Trim() == ""))
                    {
                        dtCandidateRows.Rows.Add(i, apInv.Lines.UserFields.Fields.Item("U_CostCode").Value.ToString().Trim(), apInv.Lines.AccountCode, (apInv.Lines.LineTotal), apInv.Lines.CostingCode);
                    }
                }

                int totalCnt   = dtCandidateRows.Rows.Count;
                int currentRow = 0;
                foreach (DataRow dr in dtCandidateRows.Rows)
                {
                    currentRow++;
                    oApplication.StatusBar.SetText("Processing Allocation JE (" + currentRow.ToString() + " of " + totalCnt.ToString(), BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                    string costCode = dr["AlocCode"].ToString();

                    Hashtable hp = new Hashtable();
                    hp.Add("~p1", costCode);



                    string strRulCode = Program.objHrmsUI.getQryString("141_GET_001", hp); //"select t1.U_AR from [@B1_DBOQD] t0 inner join [@B1_IBOQ] t1 on t0.U_ItemCode = t1.Code where t0.Code = '~p1' ";


                    System.Data.DataTable dtRuleCode = Program.objHrmsUI.getDataTable(strRulCode, "Getting RuleCode");
                    if (dtRuleCode == null || dtRuleCode.Rows.Count == 0)
                    {
                        oApplication.MessageBox("Cost Code not associated with Indirect BOQ to post allocaiton JE");
                        continue;
                    }

                    string allocationCode = dtRuleCode.Rows[0]["U_AR"].ToString();


                    string CreditGLCode = dr["GLCode"].ToString();
                    double CreditAmount = Convert.ToDouble(dr["Amount"]);
                    int    lineNum      = Convert.ToInt32(dr["LineNum"]);
                    string DR           = dr["DR"].ToString();
                    hp.Clear();
                    hp.Add("~p1", allocationCode);


                    string strDetails            = Program.objHrmsUI.getQryString("141_GET_002", hp);// @"Select t0.U_AP as AP , t1.U_AcctCode,t1.Code, t3.[U_BU] as BaseOn ,isnull(t1.U_FACode,'') as FA from [@B1_ARD] t0 inner join [@B1_AM] t1 on t1.Code = t0.U_CMC  inner join [@B1_AR] t3 on t3.[Code]=t0.[U_RuleCode] where t0.U_RuleCode='~p1'";
                    System.Data.DataTable dtrule = Program.objHrmsUI.getDataTable(strDetails, "Getting Rule Detail");
                    if (dtrule.Rows.Count > 0)
                    {
                        AllocationJE           = (SAPbobsCOM.JournalEntries)oCompany.GetBusinessObject(BoObjectTypes.oJournalEntries);
                        AllocationJE.Reference = allocationCode;

                        double debitTotal = 0.00;
                        foreach (DataRow drDetails in dtrule.Rows)
                        {
                            string debitAccount = drDetails["U_AcctCode"].ToString();
                            double AP           = Convert.ToDouble(drDetails["AP"]);
                            double debitAmount  = CreditAmount * AP / 100.00000;
                            string baseOn       = Convert.ToString(drDetails["BaseOn"]);
                            string FA           = Convert.ToString(drDetails["FA"]);
                            addChildJeLines(AllocationJE, drDetails["Code"].ToString(), debitAmount, debitAccount, baseOn, FA, costCode, AP.ToString());
                        }

                        for (int k = 0; k < AllocationJE.Lines.Count; k++)
                        {
                            AllocationJE.Lines.SetCurrentLine(k);
                            debitTotal += AllocationJE.Lines.Debit;
                        }

                        AllocationJE.Lines.AccountCode = CreditGLCode;
                        //  AllocationJE.Lines.Credit = debitTotal;
                        AllocationJE.Lines.Credit      = CreditAmount;
                        AllocationJE.Lines.Reference1  = allocationCode;
                        AllocationJE.Lines.CostingCode = DR;
                        AllocationJE.Lines.Add();



                        double diffAmount = CreditAmount - debitTotal;

                        if (CreditAmount != debitTotal)
                        {
                            string roundAcct = getRoundingAcct();
                            AllocationJE.Lines.AccountCode = roundAcct;

                            AllocationJE.Lines.Debit      = diffAmount;
                            AllocationJE.Lines.Reference1 = allocationCode;
                            //  AllocationJE.Lines.CostingCode = DR;
                            AllocationJE.Lines.Add();
                        }



                        if (AllocationJE.Add() != 0)
                        {
                            int    erroCode = 0;
                            string errDescr = "";
                            Program.objHrmsUI.oCompany.GetLastError(out erroCode, out errDescr);
                            oApplication.StatusBar.SetText("Failed to add Order  : " + errDescr);
                        }
                        else
                        {
                            string outStr = Convert.ToString(Program.objHrmsUI.oCompany.GetNewObjectKey());

                            hp.Clear();
                            hp.Add("~p1", outStr);
                            hp.Add("~p2", invEntry);
                            hp.Add("~p3", lineNum);

                            string updateCall = Program.objHrmsUI.getQryString("141_CRUD_001", hp);// "Update pch1 set U_AlocJE='~p1' where docentry = '~p2' and linenum='~p3'";
                            int    result     = Program.objHrmsUI.ExecQuery(updateCall, "Update Line JE");

                            oApplication.Menus.Item("1304").Activate();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                oApplication.MessageBox(ex.Message);
            }
        }