public static UserFieldsMD GetUserFieldMd(this ICompany company) { var userFieldMd = company.GetBusinessObject(BoObjectTypes.oUserFields) as UserFieldsMD; Debug.Assert(userFieldMd != null, "partner != null"); return(userFieldMd); }
public static void SqlExecute(this ICompany sboCompany, string query) { var recordSet = sboCompany.GetBusinessObject(BoObjectTypes.BoRecordset) as Recordset; try { recordSet.DoQuery(query); } finally { recordSet.ReleaseCom(); } }
public static TT SqlExecuteScalar <TT>(this ICompany sboCompany, string query) { var recordSet = sboCompany.GetBusinessObject(BoObjectTypes.BoRecordset) as Recordset; try { recordSet.DoQuery(query); return(!recordSet.EoF ? (TT)Convert.ChangeType(recordSet.Fields.Item(0).Value, typeof(TT)) : default(TT)); } finally { if (recordSet != null) { Marshal.ReleaseComObject(recordSet); } } }
private static SalesmanEntity MapToSalesmanEntity(ICompany company, ISalesPersons sameperson) { var employee = (EmployeesInfo)company.GetBusinessObject(BoObjectTypes.oEmployeesInfo); var salesman = new SalesmanEntity { Sn = sameperson.SalesEmployeeCode, Name = sameperson.SalesEmployeeName, ActiveStatus = sameperson.Active == BoYesNoEnum.tYES ? SalesmanEntity.Status.Active : SalesmanEntity.Status.NoActive }; if (!employee.GetByKey(sameperson.EmployeeID)) { return(salesman); } salesman.Mobile = employee.MobilePhone; salesman.Email = employee.eMail; return(salesman); }
public String MakePayment(int userId, int paymentId) { var user = db.DeviceUser.Where(w => w.DeviceUserId == userId).ToList().FirstOrDefault(); String connection = user.Shop == null ? "" : user.Shop.ConnectionString; using (var db = new ApplicationDbContext(connection)) { String lastMessage = ""; String key = ""; var p = db.Payments .Include(i => i.Transfer) .Include(i => i.Invoices) .Where(w => w.PaymentId == paymentId) .ToList() .FirstOrDefault(); if (p != null) { if (String.IsNullOrEmpty(p.DocEntry)) { if (_connection.Connect(connection) == 0) { company = _connection.GetCompany(); Double totalAmount = p.TotalAmount; Double amountLeft = totalAmount; Payments payment = company.GetBusinessObject(BoObjectTypes.oPaymentsDrafts); payment.DocObjectCode = BoPaymentsObjectType.bopot_IncomingPayments; payment.DocType = BoRcptTypes.rCustomer; payment.CardCode = p.Client.CardCode; payment.DocDate = DateTime.Now; payment.VatDate = DateTime.Now; payment.DueDate = DateTime.Now; payment.Remarks = p.Comment; payment.CounterReference = p.ReferenceNumber != null && p.ReferenceNumber.Count() > 20 ? p.ReferenceNumber.Substring(0, 20) : p.ReferenceNumber; if (payment.UserFields.Fields.Count > 0) { payment.UserFields.Fields.Item("U_Cobrador").Value = p.DeviceUser.CollectId; } //if (p.Cash != null) //{ // payment.CashAccount = p.Cash.GeneralAccount; // payment.CashSum = p.Cash.Amount; //} if (p.Transfer != null) { payment.TransferAccount = p.Transfer.GeneralAccount; payment.TransferDate = p.Transfer.Date; payment.TransferReference = p.Transfer.ReferenceNumber; payment.TransferSum = p.Transfer.Amount; payment.DueDate = p.Transfer.Date; } //if (p.Checks != null) //{ // foreach (Check check in p.Checks) // { // payment.Checks.CheckAccount = check.GeneralAccount; // payment.Checks.CheckSum = check.Amount; // payment.Checks.DueDate = check.DueDate; // payment.Checks.BankCode = check.Bank.FormatCode; // payment.Checks.Add(); // } //} if (p.Invoices != null) { foreach (InvoiceItem invoice in p.Invoices) { if (amountLeft > 0) { payment.Invoices.DocEntry = invoice.DocEntry; payment.Invoices.InvoiceType = BoRcptInvTypes.it_Invoice; //Si aun hay cash entonces pago la factura completa sino la pago incompleta payment.Invoices.SumApplied = invoice.PayedAmount <= amountLeft ? invoice.PayedAmount : amountLeft; amountLeft -= payment.Invoices.SumApplied; payment.Invoices.Add(); } } int errorCode = payment.Add(); if (errorCode != 0) { lastMessage = "Error Code: " + company.GetLastErrorCode().ToString() + " - " + company.GetLastErrorDescription(); } else { key = company.GetNewObjectKey(); } } payment = null; company.Disconnect(); } else { lastMessage = "Error Msg: " + _connection.GetErrorMessage().ToString(); } var pay = db.Payments .Where(w => w.PaymentId == paymentId) .ToList() .FirstOrDefault(); if (pay != null) { pay.DocEntry = key; pay.LastErrorMessage = lastMessage; pay.Status = String.IsNullOrEmpty(key) ? PaymentStatus.Error : PaymentStatus.CreadoEnSAP; db.Entry(pay).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } return(lastMessage); } }
public String MakePayment(int paymentId, int userId) { String lastMessage = ""; var user = db.DeviceUser.Where(w => w.DeviceUserId == userId).ToList().FirstOrDefault(); String connection = user.Shop == null ? "" : user.Shop.ConnectionString; var p = db.Payments .Include(i => i.Cash).Include(i => i.Transfer).Include(i => i.Checks).Include(i => i.Invoices) .ToList() .Where(w => w.PaymentId == paymentId) .FirstOrDefault(); using (var db = new ApplicationDbContext(connection)) { if (p != null) { if (_connection.Connect(connection) == 0) { company = _connection.GetCompany(); Double totalAmount = p.TotalAmount; Double amountLeft = totalAmount; Payments payment = company.GetBusinessObject(BoObjectTypes.oIncomingPayments); payment.DocType = BoRcptTypes.rCustomer; //payment.DocTypte = BoRcptTypes.rCustomer; payment.CardCode = p.Client.CardCode; payment.DocDate = DateTime.Now; payment.VatDate = DateTime.Now; payment.DueDate = DateTime.Now; if (p.Cash != null) { payment.CashAccount = p.Cash.GeneralAccount; payment.CashSum = p.Cash.Amount; } if (p.Transfer != null) { payment.TransferAccount = p.Transfer.GeneralAccount; payment.TransferDate = p.Transfer.Date; payment.TransferReference = p.Transfer.ReferenceNumber; payment.TransferSum = p.Transfer.Amount; } if (p.Checks != null) { foreach (Check check in p.Checks) { payment.Checks.CheckAccount = check.GeneralAccount; payment.Checks.CheckSum = check.Amount; payment.Checks.DueDate = check.DueDate; payment.Checks.BankCode = check.Bank.FormatCode; payment.Checks.Add(); } } if (p.Invoices != null) { var invoices = p.Invoices .Where(w => w.PaymentId == p.PaymentId) .ToList(); foreach (InvoiceItem invoice in invoices) { if (amountLeft > 0) { payment.Invoices.DocEntry = invoice.DocEntry; payment.Invoices.InvoiceType = BoRcptInvTypes.it_Invoice; //Si aun hay cash entonces pago la factura completa sino la pago incompleta payment.Invoices.SumApplied = invoice.TotalAmount <= amountLeft ? invoice.TotalAmount : amountLeft; amountLeft -= payment.Invoices.SumApplied; payment.Invoices.Add(); } } } int errorCode = payment.Add(); if (errorCode != 0) { lastMessage = "Error Code: " + company.GetLastErrorCode().ToString() + " - " + company.GetLastErrorDescription(); } else { String key = company.GetNewObjectKey(); p.DocEntry = key; db.Entry(p).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } company.Disconnect(); } else { lastMessage = "Error Msg: " + _connection.GetErrorMessage().ToString(); } p.LastErrorMessage = lastMessage; db.Entry(p).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(lastMessage); } }
private static BusinessPartner MapToBusinessPartnerEntity(ICompany company, BusinessPartner businessPartner, BusinessPartners businessPartnerSap) { businessPartner.PartnerType = businessPartnerSap.CardType switch { BoCardTypes.cCustomer => BusinessPartner.PartnerTypes.Customer, BoCardTypes.cLid => BusinessPartner.PartnerTypes.Lead, BoCardTypes.cSupplier => BusinessPartner.PartnerTypes.Supplier, _ => throw new Exception("PartnerType not recognized by sap di-api") }; businessPartner.Name = businessPartnerSap.CardName; businessPartner.Key = businessPartnerSap.CardCode; var groups = (BusinessPartnerGroups)company.GetBusinessObject(BoObjectTypes.oBusinessPartnerGroups); if (!groups.GetByKey(businessPartnerSap.GroupCode)) { Debug.WriteLine($"DiAi - group don't exist : code= {businessPartnerSap.GroupCode}"); throw new Exception($"DiAi - group don't exist : code= {businessPartnerSap.GroupCode}"); } businessPartner.GroupSn = businessPartnerSap.GroupCode; //businessPartner.Group = mapToGroupEntity(groups); businessPartner.Phone1 = businessPartnerSap.Phone1; businessPartner.Phone2 = businessPartnerSap.Phone2; businessPartner.Cellular = businessPartnerSap.Cellular; businessPartner.Email = businessPartnerSap.EmailAddress; businessPartner.Fax = businessPartnerSap.Fax; businessPartner.FederalTaxId = businessPartnerSap.FederalTaxID; businessPartner.Type = businessPartnerSap.CompanyPrivate switch { BoCardCompanyTypes.cCompany => BusinessPartner.CardType.Company, BoCardCompanyTypes.cPrivate => BusinessPartner.CardType.Private, BoCardCompanyTypes.cGovernment => BusinessPartner.CardType.Employee, _ => BusinessPartner.CardType.Company }; businessPartner.Comments = businessPartnerSap.Notes; var salesperson = (SalesPersons)company.GetBusinessObject(BoObjectTypes.oSalesPersons); if (!salesperson.GetByKey(businessPartnerSap.SalesPersonCode)) { Debug.WriteLine($"DiAi - SalePerson don't exist : code= {businessPartnerSap.SalesPersonCode}"); throw new Exception($"DiAi - SalePerson don't exist : code= {businessPartnerSap.SalesPersonCode}"); } businessPartner.SalesmanCode = businessPartnerSap.SalesPersonCode; for (var i = businessPartnerSap.Addresses.Count - 1; i >= 0 && (businessPartner.ShippingAddress == null || businessPartner.BillingAddress == null); i--) { businessPartnerSap.Addresses.SetCurrentLine(i); if (string.IsNullOrEmpty(businessPartnerSap.Addresses.AddressName)) { continue; } if (businessPartnerSap.Addresses.AddressType == BoAddressType.bo_BillTo) { businessPartner.BillingAddress = new Address(); } else { businessPartner.ShippingAddress = new Address(); } var address = businessPartnerSap.Addresses.AddressType == BoAddressType.bo_BillTo ? businessPartner.BillingAddress : businessPartner.ShippingAddress; if (address == null) { continue; } address.ID = businessPartnerSap.Addresses.AddressName; address.Country = businessPartnerSap.Addresses.Country; address.City = businessPartnerSap.Addresses.City; address.Block = businessPartnerSap.Addresses.Block; address.Street = businessPartnerSap.Addresses.Street; address.NumAtStreet = businessPartnerSap.Addresses.StreetNo; address.Apartment = businessPartnerSap.Addresses.BuildingFloorRoom; address.ZipCode = businessPartnerSap.Addresses.ZipCode; } businessPartner.IsActive = businessPartnerSap.Valid == BoYesNoEnum.tYES; businessPartner.IsVatFree = businessPartnerSap.VatLiable != BoVatStatus.vLiable; businessPartner.Balance = Convert.ToDecimal(businessPartnerSap.CurrentAccountBalance); businessPartner.Balance = Convert.ToDecimal(businessPartnerSap.CurrentAccountBalance); businessPartner.OrdersBalance = Convert.ToDecimal(businessPartnerSap.OpenOrdersBalance); businessPartner.DeliveryNotesBalance = Convert.ToDecimal(businessPartnerSap.OpenDeliveryNotesBalance); businessPartner.DiscountPercent = Convert.ToDecimal(businessPartnerSap.DiscountPercent); businessPartner.Currency = businessPartnerSap.Currency; if (!string.IsNullOrEmpty(businessPartnerSap.GlobalLocationNumber)) { businessPartner.GeoLocation = new SapGeoLocation { LocationString = businessPartnerSap.GlobalLocationNumber } } ; businessPartner.IsFavorite = businessPartnerSap.Properties[64] == BoYesNoEnum.tYES; businessPartner.IndicatorCode = businessPartnerSap.Indicator; businessPartner.IndustryCode = businessPartnerSap.Industry; businessPartner.AttachmentsCode = businessPartnerSap.AttachmentEntry != 0 ? businessPartnerSap.AttachmentEntry: new int?(); return(businessPartner); } } }