Пример #1
0
        /// <summary>
        /// Creates a business partner to the ERP.
        /// </summary>
        /// <param name="businessPartner">A model that contains the business partner
        /// info to be created.</param>
        public void Create(BusinessPartnerModel businessPartner)
        {
            // Prepare the object
            var bp = (SAPbobsCOM.BusinessPartners)_company.GetBusinessObject(BoObjectTypes.oBusinessPartners);

            // Set values
            // The built-in auto-complete procedure completes the default values of the other properties.
            bp.CardCode = businessPartner.Code;                                      //Mandatory
            bp.CardName = businessPartner.Name;
            bp.CardType = _utility.ConvertBusinessPartnerType(businessPartner.Type); //Mandatory

            // Add it to the database
            var success = bp.Add().Equals(0);

            if (!success)
            {
                // Error handling
                int    code;
                string msg;
                _company.GetLastError(out code, out msg);
                throw new Exception($"{code} {msg}");
            }

            Marshal.ReleaseComObject(bp);
        }
Пример #2
0
        public IHttpActionResult Create([FromBody] BusinessPartnerModel businessPartner)
        {
            if (businessPartner == null)
            {
                return(BadRequest());
            }

            try
            {
                _bpController.Create(businessPartner);
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #3
0
        /// <summary>
        /// Gets a single business partner details.
        /// </summary>
        /// <param name="businessPartnerCode">The code of the business partner the
        /// details of which are to be returned.</param>
        /// <returns>A model that represents the business partner info.</returns>
        public BusinessPartnerModel GetById(string businessPartnerCode)
        {
            // Prepare the object
            var bp = (SAPbobsCOM.BusinessPartners)_company.GetBusinessObject(BoObjectTypes.oBusinessPartners);

            // Find the business partner record by its code.
            BusinessPartnerModel bpModel = null;

            if (bp.GetByKey(businessPartnerCode))
            {
                bpModel      = new BusinessPartnerModel();
                bpModel.Code = bp.CardCode;
                bpModel.Name = bp.CardName;
                bpModel.Type = _utility.ConvertBusinessPartnerType(bp.CardType);
            }

            Marshal.ReleaseComObject(bp);
            return(bpModel);
        }
Пример #4
0
        public IHttpActionResult UpdateContactEmployees(string id, [FromBody] BusinessPartnerModel businessPartner)
        {
            if (businessPartner == null ||
                businessPartner.Code != id)
            {
                return(BadRequest());
            }

            try
            {
                var bpFound = _bpController.UpdateContactEmployees(id, businessPartner);
                if (!bpFound)
                {
                    return(NotFound());
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #5
0
        /// <summary>
        /// Updates contact employees of a given business partner.
        /// </summary>
        /// <param name="businessPartnerCode">The code of the business partner
        /// is to be updated.</param>
        /// <param name="businessPartner">The model that contains the new contact
        /// employee details.</param>
        /// <returns>A boolean value that is set to true whether the business partner
        /// found in the ERP.</returns>
        public bool UpdateContactEmployees(string businessPartnerCode, BusinessPartnerModel businessPartner)
        {
            // Prepare the object
            var bp = (SAPbobsCOM.BusinessPartners)_company.GetBusinessObject(BoObjectTypes.oBusinessPartners);

            // Find the record to update if exists
            var bpFound = false;

            if (bp.GetByKey(businessPartnerCode))
            {
                bpFound = true;

                foreach (var contact in businessPartner.ContactEmployees)
                {
                    if (bp.ContactEmployees.Count > 0)
                    {
                        bp.ContactEmployees.Add();
                    }

                    bp.ContactEmployees.Name   = contact.Name;
                    bp.ContactEmployees.E_Mail = contact.Email;
                }

                var success = bp.Update().Equals(0);
                if (!success)
                {
                    // Error handling
                    int    code;
                    string msg;
                    _company.GetLastError(out code, out msg);
                    throw new Exception($"{code} {msg}");
                }
            }

            Marshal.ReleaseComObject(bp);
            return(bpFound);
        }
Пример #6
0
        public JsonResult CustomerSave(BusinessPartnerModel model, int mode = 0)
        {
            var jsonReturn = new JsonResponse();

            using (var db = new FTTxEntities())
            {
                try
                {
                    string responseMessage = String.Empty;
                    var    sap             = new FTTx();

                    model.Cellular = new StringBuilder(System.Text.RegularExpressions.Regex.Replace(model.Cellular, "[^0-9]", "")).ToString();

                    if (mode == 0)
                    {
                        string prefix       = "C";
                        int    newCode      = 1;
                        var    lastCardCode = db.OCRD.Where(r => r.CardCode.Substring(0, 3) == prefix + model.ProvinceId).OrderByDescending(r => r.CardCode.Substring(4)).Select(r => r.CardCode.Substring(3)).FirstOrDefault();
                        if (lastCardCode != null)
                        {
                            newCode = int.Parse(lastCardCode) + 1;
                        }

                        model.CustomerCode = string.Format("{0}{1}{2}", prefix, model.ProvinceId, newCode.ToString().PadLeft(6, '0'));

                        sap.Connecting(out responseMessage);
                        if (sap.company.Connected)
                        {
                            SAPbobsCOM.BusinessPartners bp = (SAPbobsCOM.BusinessPartners)sap.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
                            bp.GroupCode    = 103;
                            bp.CardType     = SAPbobsCOM.BoCardTypes.cCustomer;
                            bp.CardCode     = model.CustomerCode;
                            bp.CardName     = model.CustomerName;
                            bp.FederalTaxID = model.CardNo;
                            bp.Frozen       = model.FrozenFor == "Y" ? SAPbobsCOM.BoYesNoEnum.tYES : SAPbobsCOM.BoYesNoEnum.tNO;
                            bp.Address      = model.Address;
                            bp.Block        = model.District;
                            bp.County       = model.Amphur;
                            bp.City         = model.ProvinceName;
                            bp.ZipCode      = model.Zipcode;
                            bp.Cellular     = model.Cellular;
                            bp.EmailAddress = model.Email;

                            bp.MailAddress           = model.Address;
                            bp.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_ShipTo;
                            bp.Addresses.AddressName = "Ship to";
                            bp.Addresses.Block       = model.District;
                            bp.Addresses.County      = model.Amphur;
                            bp.Addresses.City        = model.ProvinceName;
                            bp.Addresses.ZipCode     = model.Zipcode;
                            if (!string.IsNullOrEmpty(model.Cellular))
                            {
                                bp.UserFields.Fields.Item("U_InsTel").Value = model.Cellular;
                            }

                            if (!string.IsNullOrEmpty(model.Address))
                            {
                                bp.UserFields.Fields.Item("U_StmAddr").Value = bp.Address;
                            }
                            if (!string.IsNullOrEmpty(model.District))
                            {
                                bp.UserFields.Fields.Item("U_StmBlck").Value = model.District;
                            }
                            if (!string.IsNullOrEmpty(model.Amphur))
                            {
                                bp.UserFields.Fields.Item("U_StmCnty").Value = model.Amphur;
                            }
                            if (!string.IsNullOrEmpty(model.ProvinceName))
                            {
                                bp.UserFields.Fields.Item("U_StmCity").Value = model.ProvinceName;
                            }
                            if (!string.IsNullOrEmpty(model.Zipcode))
                            {
                                bp.UserFields.Fields.Item("U_StmZipC").Value = model.Zipcode;
                            }
                            if (!string.IsNullOrEmpty(model.Cellular))
                            {
                                bp.UserFields.Fields.Item("U_Bphone").Value = model.Cellular;
                            }

                            if (0 != bp.Add())
                            {
                                jsonReturn = new JsonResponse {
                                    status = false, message = sap.company.GetLastErrorDescription()
                                };
                            }
                            else
                            {
                                jsonReturn = new JsonResponse {
                                    status = true, message = "บันทึกข้อมูลเรียบร้อยแล้ว"
                                };
                            }

                            sap.company.Disconnect();
                        }
                        else
                        {
                            jsonReturn = new JsonResponse()
                            {
                                status = false, message = responseMessage
                            };
                        }
                    }
                    else
                    {
                        sap.Connecting(out responseMessage);
                        if (sap.company.Connected)
                        {
                            SAPbobsCOM.BusinessPartners bp = (SAPbobsCOM.BusinessPartners)sap.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
                            bp.GetByKey(model.CustomerCode);

                            bp.CardName     = model.CustomerName;
                            bp.FederalTaxID = model.CardNo;
                            bp.Frozen       = model.FrozenFor == "Y" ? SAPbobsCOM.BoYesNoEnum.tYES : SAPbobsCOM.BoYesNoEnum.tNO;
                            bp.Address      = model.Address;
                            bp.Block        = model.District;
                            bp.County       = model.Amphur;
                            bp.City         = model.ProvinceName;
                            bp.ZipCode      = model.Zipcode;
                            bp.Cellular     = model.Cellular;
                            bp.EmailAddress = model.Email;

                            bp.MailAddress       = model.Address;
                            bp.Addresses.Block   = model.District;
                            bp.Addresses.County  = model.Amphur;
                            bp.Addresses.City    = model.ProvinceName;
                            bp.Addresses.ZipCode = model.Zipcode;
                            if (!string.IsNullOrEmpty(model.Cellular))
                            {
                                bp.UserFields.Fields.Item("U_InsTel").Value = model.Cellular;
                            }

                            if (!string.IsNullOrEmpty(model.Address))
                            {
                                bp.UserFields.Fields.Item("U_StmAddr").Value = bp.Address;
                            }
                            if (!string.IsNullOrEmpty(model.District))
                            {
                                bp.UserFields.Fields.Item("U_StmBlck").Value = model.District;
                            }
                            if (!string.IsNullOrEmpty(model.Amphur))
                            {
                                bp.UserFields.Fields.Item("U_StmCnty").Value = model.Amphur;
                            }
                            if (!string.IsNullOrEmpty(model.ProvinceName))
                            {
                                bp.UserFields.Fields.Item("U_StmCity").Value = model.ProvinceName;
                            }
                            if (!string.IsNullOrEmpty(model.Zipcode))
                            {
                                bp.UserFields.Fields.Item("U_StmZipC").Value = model.Zipcode;
                            }
                            if (!string.IsNullOrEmpty(model.Cellular))
                            {
                                bp.UserFields.Fields.Item("U_Bphone").Value = model.Cellular;
                            }

                            if (0 != bp.Update())
                            {
                                jsonReturn = new JsonResponse {
                                    status = false, message = sap.company.GetLastErrorDescription()
                                };
                            }
                            else
                            {
                                jsonReturn = new JsonResponse {
                                    status = true, message = "บันทึกข้อมูลเรียบร้อยแล้ว"
                                };
                            }

                            sap.company.Disconnect();
                        }
                        else
                        {
                            jsonReturn = new JsonResponse()
                            {
                                status = false, message = responseMessage
                            };
                        }
                    }
                }
                catch (Exception ex)
                {
                    jsonReturn = new JsonResponse {
                        status = false, message = ex.Message
                    };
                    Log.Error(this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " Error -> " + ex.Message);
                }
            }
            return(Json(jsonReturn));
        }
Пример #7
0
 /// <summary>
 /// Updates contact employees of a given business partner.
 /// </summary>
 /// <param name="businessPartnerCode">The code of the business partner
 /// is to be updated.</param>
 /// <param name="businessPartner">The model that contains the new contact
 /// employee details.</param>
 /// <returns>A boolean value that is set to true whether the business partner
 /// found in the ERP.</returns>
 public bool UpdateContactEmployees(string businessPartnerCode, BusinessPartnerModel businessPartner)
 {
     return(true);
 }
Пример #8
0
 /// <summary>
 /// Creates a business partner to the ERP.
 /// </summary>
 /// <param name="businessPartner">A model that contains the business partner
 /// info to be created.</param>
 public void Create(BusinessPartnerModel businessPartner)
 {
 }