Example #1
0
        private List <JournalLineDTO> AddAsset(List <JournalLineDTO> pLstJELine, CommissionDriverDTO pObjInvoices)
        {
            List <CommissionDriverDTO> lLstCmsDriverDTO = new List <CommissionDriverDTO>();

            lLstCmsDriverDTO = mObjTransportsFactory.GetCommissionService().GetCommissionDriverLine(pObjInvoices.Folio);
            foreach (JournalLineDTO lObjLine in pLstJELine)
            {
                lLstCmsDriverDTO = lLstCmsDriverDTO.Where(x => x.DriverId == lObjLine.Auxiliar).GroupBy(g => g.AF).Select(y => new CommissionDriverDTO {
                    DriverId = y.First().DriverId,
                    AF       = y.First().AF,
                    Comm     = y.Sum(s => s.Comm),
                }).ToList();

                if (lLstCmsDriverDTO.Count > 0)
                {
                    lObjLine.CostingCode2 = mObjTransportsFactory.GetCommissionService().GetAsset(lLstCmsDriverDTO.OrderBy(x => x.TotComm).Take(1).First().AF);
                }
            }
            return(pLstJELine);
        }
        private void CreateJournalEntry()
        {
            try
            {
                if (cboAcct.Selected == null)
                {
                    UIApplication.ShowError("Seleccione una cuenta");
                    return;
                }

                string lStrBankAccountNum = cboAcct.Selected.Value;
                if (string.IsNullOrEmpty(lStrBankAccountNum))
                {
                    UIApplication.ShowError("Seleccione una cuenta");
                    return;
                }

                string lStrBankAccountCode = mObjTransportServiceFactory.GetBankService().GetBankAccount(lStrBankAccountNum).GLAccount;
                string lStrFolio           = txtFolio.Value;
                string lStrReference       = txtReference.Value;
                string lStrCmsDriverAcct   = new QueryManager().GetValue("U_VALUE", "Name", "TR_ACC_LIQCHOF", "[@UG_Config]");
                string lStrFilePath        = string.Empty;

                if (string.IsNullOrEmpty(lStrFolio))
                {
                    UIApplication.ShowError("Seleccione un folio de comisión");
                    return;
                }

                if (string.IsNullOrEmpty(lStrBankAccountCode))
                {
                    UIApplication.ShowError(string.Format("No se encontró la cuenta para la cuenta bancaria {0}", lStrBankAccountNum));
                    return;
                }

                if (string.IsNullOrEmpty(lStrCmsDriverAcct))
                {
                    UIApplication.ShowError("Agregue un valor en la configuración para el campo TR_ACC_LIQCHOF");
                    return;
                }

                if (dtCommissions.Rows.Count == 0)
                {
                    UIApplication.ShowError("No puede crear la comisión sin líneas");
                    return;
                }

                if (!string.IsNullOrEmpty(mStrFilePath))
                {
                    //mObjTransportServiceFactory.GetAttachmentDI().AttachFile(mStrFilePath);
                    lStrFilePath = AttatchFile(mStrFilePath);
                }

                SAPbobsCOM.JournalEntries lObjJournalEntry = (SAPbobsCOM.JournalEntries)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries);
                lObjJournalEntry.TransactionCode = "TRPG";
                lObjJournalEntry.Reference       = lStrFolio;
                lObjJournalEntry.Reference2      = lStrReference;
                lObjJournalEntry.ReferenceDate   = DateTime.Now;
                lObjJournalEntry.TaxDate         = DateTime.Now;
                lObjJournalEntry.DueDate         = DateTime.Now;

                for (int i = 0; i < dtCommissions.Rows.Count; i++)
                {
                    string lStrEmpId     = dtCommissions.GetValue("EmpId", i).ToString();
                    string lStrEmployee  = dtCommissions.GetValue("EmpNm", i).ToString();
                    double lDblImport    = double.Parse(dtCommissions.GetValue("Import", i).ToString());
                    string lStrFolioLine = dtCommissions.GetValue("FolioCms", i).ToString();
                    string lStrAcctLine  = dtCommissions.GetValue("Acct", i).ToString();

                    lObjJournalEntry.Lines.SetCurrentLine(lObjJournalEntry.Lines.Count - 1);
                    lObjJournalEntry.Lines.TaxDate     = DateTime.Now;
                    lObjJournalEntry.Lines.AccountCode = lStrCmsDriverAcct;
                    lObjJournalEntry.Lines.Debit       = lDblImport;
                    lObjJournalEntry.Lines.Credit      = 0;
                    lObjJournalEntry.Lines.CostingCode = "TR_TRANS";
                    lObjJournalEntry.Lines.UserFields.Fields.Item("U_GLO_TypeAux").Value  = "2";
                    lObjJournalEntry.Lines.UserFields.Fields.Item("U_GLO_Auxiliar").Value = lStrEmpId; //code empleado
                    lObjJournalEntry.Lines.UserFields.Fields.Item("U_GLO_CodeMov").Value  = lStrFolio;
                    lObjJournalEntry.Lines.UserFields.Fields.Item("U_GLO_File").Value     = lStrFilePath;

                    lObjJournalEntry.Lines.Add();

                    lObjJournalEntry.Lines.SetCurrentLine(lObjJournalEntry.Lines.Count - 1);
                    lObjJournalEntry.Lines.TaxDate     = DateTime.Now;
                    lObjJournalEntry.Lines.AccountCode = lStrBankAccountCode;
                    lObjJournalEntry.Lines.Debit       = 0;
                    lObjJournalEntry.Lines.Credit      = lDblImport;
                    lObjJournalEntry.Lines.CostingCode = "TR_TRANS";
                    lObjJournalEntry.Lines.UserFields.Fields.Item("U_GLO_TypeAux").Value  = "2";
                    lObjJournalEntry.Lines.UserFields.Fields.Item("U_GLO_Auxiliar").Value = lStrEmpId; //code empleado
                    lObjJournalEntry.Lines.UserFields.Fields.Item("U_GLO_CodeMov").Value  = lStrFolio;
                    lObjJournalEntry.Lines.UserFields.Fields.Item("U_GLO_File").Value     = lStrFilePath;

                    lObjJournalEntry.Lines.Add();
                }

                if (lObjJournalEntry.Add() != 0)
                {
                    string lStrLastError = DIApplication.Company.GetLastErrorDescription();
                    UIApplication.ShowMessageBox(string.Format("Error al generar el asiento de la comisión: {0}", DIApplication.Company.GetLastErrorDescription()));
                }
                else
                {
                    int lIntDocEntry = int.Parse(DIApplication.Company.GetNewObjectKey());

                    LogUtility.WriteSuccess(String.Format("[frmDriversCommissions - CreateJournalEntry] Comisión creada correctamente con el DocEntry {0} para el Folio: {1}", lIntDocEntry, lStrFolio));

                    Commissions lObjCommission = mObjTransportServiceFactory.GetCommissionService().GetCommission(lStrFolio);
                    lObjCommission.HasDriverCms = "Y";

                    if (mObjTransportServiceFactory.GetCommissionService().UpdateCommission(lObjCommission) != 0)
                    {
                        throw new Exception(string.Format("Error al modificar el estatus de la comisión {0}", lStrFolio));
                    }


                    //SaveCommissionsRecords(lIntDocEntry);

                    ClearControls();

                    UIApplication.ShowSuccess(string.Format("Comisión creada correctamente con el número de documento: {0}", lIntDocEntry));
                }
            }
            catch (Exception lObjException)
            {
                LogUtility.WriteError(String.Format("[frmDriversCommissions - CreateJournalEntry] Error al crear el asiento contable: {0}", lObjException.Message));
                throw new Exception(string.Format("Error al crear el asiento contable: {0}", lObjException.Message));
            }
            finally
            {
            }
        }