private void OnCustomInitialize()
        {
            try
            {
                string lStrCostCenter = mObjPurchasesServiceFactory.GetPurchaseInvoiceService().GetCostCenter();
                //PermissionsEnum.Permission lObjPermissionEnum = mObjPurchasesServiceFactory.GetPurchasePermissionsService().GetPermissionType(lStrCostCenter, "U_GLO_ExpeCheck");
                string lStrCCTypeCode = mObjPurchasesServiceFactory.GetPurchaseInvoiceService().CCTypeCode(lStrCostCenter);
                HiddecontrolsPayments();
                if (lStrCCTypeCode == "O")
                {
                    txtArea.Value = lStrCostCenter;
                    txtEmploye.Item.Click();
                    txtArea.Item.Enabled = false;
                }
                else
                {
                    txtArea.Item.Enabled = true;
                    LoadChooseFromList();
                    SetChooseToTxt();
                }

                LoadCombobox();
                cbAccount.ValidValues.Add("", "");
                mtxRefound.AutoResizeColumns();
            }
            catch (Exception ex)
            {
                LogService.WriteError("frmSearchRefunds (OnCustomInitialize) " + ex.Message);
                LogService.WriteError(ex);
            }
        }
Beispiel #2
0
        public void AddMenuItems()
        {
            SAPbouiCOM.Menus    oMenus    = null;
            SAPbouiCOM.MenuItem oMenuItem = null;

            oMenus = Application.SBO_Application.Menus;

            SAPbouiCOM.MenuCreationParams oCreationPackage = null;
            oCreationPackage = ((SAPbouiCOM.MenuCreationParams)(Application.SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)));
            oMenuItem        = Application.SBO_Application.Menus.Item("43520"); // moudles'

            oCreationPackage.Type     = SAPbouiCOM.BoMenuType.mt_POPUP;
            oCreationPackage.UniqueID = "UGRS.AddOn.Purchases";
            oCreationPackage.String   = "Compras";
            oCreationPackage.Enabled  = true;
            oCreationPackage.Position = -1;

            oMenus = oMenuItem.SubMenus;

            try
            {
                //  If the manu already exists this code will fail
                oMenus.AddEx(oCreationPackage);
            }
            catch (Exception)
            {
            }

            try
            {
                // Get the menu collection of the newly added pop-up item
                oMenuItem = Application.SBO_Application.Menus.Item("UGRS.AddOn.Purchases");
                oMenus    = oMenuItem.SubMenus;

                //// Create s sub menu
                //oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING;
                //oCreationPackage.UniqueID = "UGRS.AddOn.Purchases.Form1";
                //oCreationPackage.String = "Notas";
                //oMenus.AddEx(oCreationPackage);

                //// Create s sub menu
                //oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING;
                //oCreationPackage.UniqueID = "UGRS.AddOn.Purchases.frmPurchaseXML";
                //oCreationPackage.String = "XML";
                //oMenus.AddEx(oCreationPackage);

                // Create s sub menu

                DIApplication.DIConnect((SAPbobsCOM.Company)Application.SBO_Application.Company.GetDICompany());
                string lStrCostCenter = mObjPurchasesServiceFactory.GetPurchaseInvoiceService().GetCostCenter();

                /* if (mObjPurchasesServiceFactory.GetPurchasePermissionsService().GetPermissionType(lStrCostCenter, "U_GLO_Refund") != PermissionsEnum.Permission.None)
                 * {*/
                oCreationPackage.Type     = SAPbouiCOM.BoMenuType.mt_STRING;
                oCreationPackage.UniqueID = "UGRS.AddOn.Purchases.frmReceipts";
                oCreationPackage.String   = "Captura de comprobantes";
                oMenus.AddEx(oCreationPackage);

                // Create s sub menu
                oCreationPackage.Type     = SAPbouiCOM.BoMenuType.mt_STRING;
                oCreationPackage.UniqueID = "UGRS.AddOn.Purchases.frmSearchRefunds";
                oCreationPackage.String   = "Búsqueda de reembolsos";
                oMenus.AddEx(oCreationPackage);

                /* }
                 *
                 *
                 * if (mObjPurchasesServiceFactory.GetPurchasePermissionsService().GetPermissionType(lStrCostCenter, "U_GLO_ExpeCheck") != PermissionsEnum.Permission.None)
                 * {*/

                // Create s sub menu
                oCreationPackage.Type     = SAPbouiCOM.BoMenuType.mt_STRING;
                oCreationPackage.UniqueID = "UGRS.AddOn.Purchases.frmCheeckingCosts";
                oCreationPackage.String   = "Comprobación de gastos";
                oMenus.AddEx(oCreationPackage);
                // }

                // Create s sub menu
                oCreationPackage.Type     = SAPbouiCOM.BoMenuType.mt_STRING;
                oCreationPackage.UniqueID = "UGRS.AddOn.Purchases.frmXML";
                oCreationPackage.String   = "Carga de xml";
                oMenus.AddEx(oCreationPackage);
            }
            catch (Exception)
            { //  Menu already exists
                Application.SBO_Application.SetStatusBarMessage("Menu Already Exists", SAPbouiCOM.BoMessageTime.bmt_Short, true);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Crear factura.
        /// </summary>
        public bool CreateDocument(PurchaseXMLDTO pObjPurchase, bool lBolCreatePayment)
        {
            bool   lBolIsSuccess = false;
            string lStrAttachXML = string.Empty;
            string lStrAttachPDF = string.Empty;

            //SAPbobsCOM.Documents lObjDocument = (SAPbobsCOM.Documents)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices);
            SAPbobsCOM.Documents lObjDocument = (SAPbobsCOM.Documents)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);
            try
            {
                //Draft Type Document
                lObjDocument.DocObjectCode = BoObjectTypes.oPurchaseInvoices;

                /*double ldbl = Convert.ToDouble(pObjPurchase.Total);
                 * lObjDocument.DocTotal = ldbl;*/
                string lStrCostCenter = mObjPurchaseServiceFactory.GetPurchaseInvoiceService().GetCostCenter();

                lObjDocument.CardCode   = pObjPurchase.CardCode;
                lObjDocument.EDocNum    = pObjPurchase.FolioFiscal;
                lObjDocument.TaxDate    = pObjPurchase.TaxDate;
                lObjDocument.DocDate    = pObjPurchase.DocDate;
                lObjDocument.Comments   = pObjPurchase.Obs;
                lObjDocument.NumAtCard  = pObjPurchase.ReferenceFolio;
                lObjDocument.DocDueDate = pObjPurchase.TaxDate.AddMonths(1);
                lObjDocument.UserFields.Fields.Item("U_UDF_UUID").Value = pObjPurchase.FolioFiscal;
                //lObjDocument.UserFields.Fields.Item("U_GLO_DocEUG").Value = String.IsNullOrEmpty(pObjPurchase.CodeMov) ? "" : pObjPurchase.CodeMov;
                lObjDocument.UserFields.Fields.Item("U_GLO_ObjTUG").Value  = "frmReceipts";
                lObjDocument.UserFields.Fields.Item("U_FolioFiscal").Value = pObjPurchase.FolioFiscal;
                lObjDocument.UserFields.Fields.Item("U_GLO_Memo").Value    = pObjPurchase.Obs;
                string lStrFile = AttatchFile(pObjPurchase.XMLFile);
                if (!string.IsNullOrEmpty(lStrFile))
                {
                    lObjDocument.UserFields.Fields.Item("U_ArchivoXML").Value = AttatchFile(pObjPurchase.XMLFile);
                    lObjDocument.UserFields.Fields.Item("U_ArchivoPDF").Value = AttatchFile(pObjPurchase.PDFFile);
                }
                else
                {
                    return(false);
                }

                lObjDocument.UserFields.Fields.Item("U_MQ_Rise").Value = pObjPurchase.MQRise;
                // lObjDocument.WithholdingTaxData

                //adding reference
                lObjDocument.UserFields.Fields.Item("U_MQ_OrigenFol").Value = pObjPurchase.Folio;                /* (String.IsNullOrEmpty(pObjPurchase.CodeMov)) ?
                                                                                                                  * String.Format("{0}_{1}_{2}", pObjPurchase.Type, pObjPurchase.Area, pObjPurchase.Folio) :
                                                                                                                  * String.Format(pObjPurchase.Type +"_"+ pObjPurchase.CodeMov);*/


                lObjDocument.UserFields.Fields.Item("U_MQ_OrigenFol_Det").Value = pObjPurchase.RowLine;

                bool lbolWithholdingTax = true;

                /*Base = y.First().Base,
                 *      Tax = y.First().Tax,
                 *      TypeFactor = y.First().TypeFactor,
                 *      Rate = y.First().Rate,
                 *      Amount = y.Sum(c => float.Parse(c.Amount)).ToString()*/

                pObjPurchase.WithholdingTax = pObjPurchase.WithholdingTax.GroupBy(x => x.Rate).Select(y => new TaxesXMLDTO
                {
                    Base       = y.First().Base,
                    Tax        = y.First().Tax,
                    TypeFactor = y.First().TypeFactor,
                    Rate       = y.First().Rate,
                    Amount     = y.Sum(c => float.Parse(c.Amount)).ToString()
                }).ToList();



                foreach (TaxesXMLDTO lObjTax in pObjPurchase.WithholdingTax)
                {
                    lObjDocument.WithholdingTaxData.WTCode = mObjPurchaseServiceFactory.GetPurchaseInvoiceService().GetWithholdingTaxCodeBP(Convert.ToDouble(lObjTax.Rate) * 100, lObjDocument.CardCode);
                    if (!string.IsNullOrEmpty(lObjDocument.WithholdingTaxData.WTCode))
                    {
                        lObjDocument.WithholdingTaxData.WTAmount = Convert.ToDouble(lObjTax.Amount);
                        lObjDocument.WithholdingTaxData.Add();
                    }
                    else
                    {
                        lbolWithholdingTax = false;
                    }
                }


                foreach (ConceptsXMLDTO lObjConcept in pObjPurchase.ConceptLines)
                {
                    lObjDocument.Lines.ItemCode        = lObjConcept.CodeItmProd;
                    lObjDocument.Lines.UnitPrice       = Convert.ToDouble(lObjConcept.UnitPrice);
                    lObjDocument.Lines.Quantity        = Convert.ToDouble(lObjConcept.Quantity);
                    lObjDocument.Lines.COGSCostingCode = lObjConcept.CostingCode;
                    if (lObjConcept.AdmOper == "O")
                    {
                        lObjDocument.Lines.AccountCode = mObjPurchaseServiceFactory.GetPurchaseInvoiceService().GetCostAccount(lObjConcept.CodeItmProd);
                    }

                    lObjDocument.Lines.TaxType  = lObjConcept.HasTax ? BoTaxTypes.tt_Yes : BoTaxTypes.tt_No;                     //= BoTaxTypes.tt_No;
                    lObjDocument.Lines.WTLiable = lObjConcept.HasWht ? BoYesNoEnum.tYES : BoYesNoEnum.tNO;
                    lObjDocument.Lines.UserFields.Fields.Item("U_CO_AdmOper").Value = lObjConcept.AdmOper;

                    lObjDocument.Lines.COGSCostingCode2 = lObjConcept.AF;
                    lObjDocument.Lines.ProjectCode      = lObjConcept.Project;
                    lObjDocument.Lines.CostingCode3     = lObjConcept.AGL;

                    //lObjDocument.Lines.
                    lObjDocument.Lines.TaxCode = lObjConcept.TaxCode;
                    //lObjDocument.Lines.TaxTotal = lObjConcept.LstTaxes;
                    if (!string.IsNullOrEmpty(pObjPurchase.MQRise))
                    {
                        string lStrWhsMQ = mObjPurchaseServiceFactory.GetPurchaseInvoiceService().GetMQWhs(lObjConcept.CodeItmProd);
                        if (!string.IsNullOrEmpty(lStrWhsMQ))
                        {
                            lObjConcept.WareHouse = lStrWhsMQ;
                        }
                    }
                    lObjDocument.Lines.WarehouseCode = lObjConcept.WareHouse;                     //mObjPurchaseServiceFactory.GetPurchaseInvoiceService().GetWhouse(lObjConcept.CostingCode);

                    double lDblDesc = 0;
                    if (Convert.ToDecimal(lObjConcept.Discount) > 0)
                    {
                        lDblDesc = Convert.ToDouble(lObjConcept.Discount) / Convert.ToDouble(lObjConcept.Subtotal);
                        //lDblDesc = Math.Round(100 * lDblDesc) / 100;
                        lObjDocument.Lines.DiscountPercent = lDblDesc * 100;
                    }


                    double lDblUnitPrice = Convert.ToDouble(lObjConcept.UnitPrice);
                    lDblUnitPrice = Math.Round(100 * lDblUnitPrice) / 100;

                    double lDblQuantity  = Convert.ToDouble(lObjConcept.Quantity);
                    double lDblAmountXML = Convert.ToDouble(lObjConcept.Subtotal);

                    double lDblAmount = lDblUnitPrice * lDblQuantity;

                    lDblAmount    = Math.Round(100 * lDblAmount) / 100;
                    lDblAmountXML = Math.Round(100 * lDblAmountXML) / 100;


                    if (lDblAmount != lDblAmountXML)
                    {
                        double lDblnewDesc = 0;
                        lDblnewDesc = (lDblAmount / lDblAmountXML) - 1;
                        lObjDocument.Lines.DiscountPercent += lDblnewDesc * 100;
                    }
                    //lObjDocument.Lines.LineTotal = Convert.ToDouble(lObjConcept.Amount);
                    lObjDocument.Lines.Add();


                    // lObjDocument.Lines.
                }



                if (lbolWithholdingTax)
                {
                    if (lObjDocument.Add() != 0)
                    {
                        string lStrError = DIApplication.Company.GetLastErrorDescription();
                        UIApplication.ShowMessageBox(string.Format("Exception: {0}", DIApplication.Company.GetLastErrorDescription()));
                        LogService.WriteError("InvoiceDI (CreateDocument) " + DIApplication.Company.GetLastErrorDescription());
                    }
                    else
                    {
                        lBolIsSuccess = true;

                        string lStrDocEntry = DIApplication.Company.GetNewObjectKey().ToString();


                        pObjPurchase.DocEntry = Convert.ToInt32(lStrDocEntry);
                        PaymentDI lObjPaymentDI = new PaymentDI();

                        //SAPbobsCOM.Documents lObjDocInvoice = (SAPbobsCOM.Documents)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices);
                        SAPbobsCOM.Documents lObjDocInvoice = (SAPbobsCOM.Documents)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);
                        lObjDocInvoice.GetByKey(Convert.ToInt32(lStrDocEntry));

                        pObjPurchase.Total = lObjDocInvoice.DocTotal.ToString();

                        if (lBolCreatePayment)
                        {
                            //lBolIsSuccess = lObjPaymentDI.CreatePayment(pObjPurchase);
                            //AddVoucherDetail(pObjPurchase, pObjVoucher);
                        }

                        if (lBolIsSuccess)
                        {
                            LogService.WriteSuccess("Documento realizado correctamente: " + lStrDocEntry);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lBolIsSuccess = false;
                UIApplication.ShowMessageBox(string.Format(ex.Message + "\n" + "Exception: {0}", DIApplication.Company.GetLastErrorDescription()));
                LogService.WriteError("InvoiceDI (CreateDocument) " + DIApplication.Company.GetLastErrorDescription());
                LogService.WriteError("InvoiceDI (CreateDocument) " + ex.Message);
                LogService.WriteError(ex);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjDocument);
            }
            return(lBolIsSuccess);
        }