示例#1
0
 public void CreateShipment(string orderDescription)
 {
     try
     {
         using (JoinedSqlTransactionScope sqlTrans = new JoinedSqlTransactionScope())
         {
             var OrderHeaderID = FindOrderHeaderIDByDescription(orderDescription);
             if (!OrderHeaderID.HasValue)
             {
                 throw new Exception("CreateShipment=> B2C order id:" + orderDescription + "can not find order from B2C id");
             }
             NebimV3.Orders.RetailSale order = new NebimV3.Orders.RetailSale(OrderHeaderID.Value);
             //order.get
             NebimV3.Shipments.RetailSale newShipment = CreateRetailSaleShipment(order, "", null);
             CreateRetailSaleShipmentLinesFromOrderLines(order, newShipment);
             newShipment.SaveAsCompleted();
             sqlTrans.Commit();
         }
     }
     catch (Exception ex)
     {
         NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
         if (v3Ex != null)
         {
             throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
         }
         throw;
     }
 }
示例#2
0
 // Elimizde order nesnesi var ise
 public void SavePayment(NebimV3.Orders.RetailSale order, myPaymentTypes paymentType, string creditCardTypeCode, byte installment, string maskedCCNo, string provisionNo)
 {
     try
     {
         if (paymentType == myPaymentTypes.bank)
         {
             this.SavePaymentByBank(order);
         }
         else if (paymentType == myPaymentTypes.cash)
         {
             this.SavePaymentByCash(order, _nebimIntegrationSettings.API_CashAccountCode);//cashAccountCode="100.01.001"
         }
         else
         {
             this.SavePaymentByCreditCard(order, creditCardTypeCode, installment, maskedCCNo, provisionNo);
         }
     }
     catch (Exception ex)
     {
         NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
         if (v3Ex != null)
         {
             throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
         }
         throw;
     }
 }
示例#3
0
        private Guid?FindOrderHeaderIDByDescription(string description)
        {
            if (string.IsNullOrWhiteSpace(description))
            {
                return(null);
            }
            try
            {
                NebimV3.DataConnector.SqlSelectStatement query = new NebimV3.DataConnector.SqlSelectStatement();
                query.TableNames.Add("trOrderHeader", false);

                query.Parameters.Add(new NebimV3.DataConnector.PropertyCondition("trOrderHeader", "Description"));
                query.Parameters.Add(new NebimV3.DataConnector.PropertyCondition("trOrderHeader", "OrderHeaderID"));
                query.Filter = new NebimV3.DataConnector.GroupCondition();

                if (description != null)
                {
                    query.Filter.AddCondition(
                        new NebimV3.DataConnector.BinaryCondition(
                            new NebimV3.DataConnector.PropertyCondition("trOrderHeader", "Description"),
                            new NebimV3.DataConnector.ValueCondition(description)
                            ));
                }


                HashSet <Guid> results = new HashSet <Guid>();

                using (System.Data.IDataReader reader = NebimV3.DataConnector.SqlStatmentExecuter.ExecuteSelect(query))
                {
                    while (reader.Read())
                    {
                        results.Add((Guid)(reader["OrderHeaderID"]));
                    }
                }

                // if (results.Count > 1)  // Örnek olarak yaptik. Exception atmak yerine ne yapilmasi gerektigi uygulamaya göre degisebilir.
                //     throw new Exception("More than one record with the same B2C customer Id");

                if (results.Count == 0)
                {
                    return(null);
                }

                return(results.LastOrDefault());
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
        }
示例#4
0
 //creates the shipment event => stock inventory update
 private void CreateShipment(NebimV3.Orders.RetailSale order)
 {
     try
     {
         using (JoinedSqlTransactionScope sqlTrans = new JoinedSqlTransactionScope())
         {
             NebimV3.Shipments.RetailSale newShipment = CreateRetailSaleShipment(order, "", null);
             CreateRetailSaleShipmentLinesFromOrderLines(order, newShipment);
             newShipment.SaveAsCompleted();
             sqlTrans.Commit();
         }
     }
     catch (Exception ex)
     {
         NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
         if (v3Ex != null)
         {
             throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
         }
         throw;
     }
 }
示例#5
0
        public string CreateOrder(string description, DateTime?orderDate, string customerCode, Guid?shippingPostalAddressID, Guid?BillingPostalAddressID,
                                  IList <Tuple <string, string, string, string, int, decimal?, decimal?, Tuple <string> > > items,
                                  decimal?discountAmount, double?discountRate, string currencyCode, decimal shippingCost, decimal giftBoxCost, string discountNames)
        {
            try
            {
                using (NebimV3.DataConnector.JoinedSqlTransactionScope sqlTrans = new JoinedSqlTransactionScope())
                {
                    NebimV3.Orders.RetailSale order = new NebimV3.Orders.RetailSale();

                    // Required fields
                    order.OrderDate       = orderDate.HasValue ? orderDate.Value : NebimV3.ApplicationCommon.V3Application.Context.Today;          // Or --> order.OrderDate = new DateTime(2011, 12, 05)
                    order.OrderTime       = orderDate.HasValue ? orderDate.Value.TimeOfDay : NebimV3.ApplicationCommon.V3Application.Context.Time; // (Optional)
                    order.OfficeCode      = _nebimIntegrationSettings.API_OfficeCode;                                                              // "O-2": Daimamoda
                    order.WarehouseCode   = _nebimIntegrationSettings.API_WarehouseCode;                                                           // "1-2-1-1": Daimamoda Merkez
                    order.DocCurrencyCode = currencyCode;
                    order.DocumentNumber  = description;
                    order.CustomerCode    = customerCode;
                    if (!order.Customer.ExistsInDB())
                    {
                        throw new Exception("Order customer does not exists. CustomerCode:" + customerCode);
                    }

                    order.Customer.Load();
                    order.Customer.CurrAccDefault.Load();
                    order.Customer.AllPostalAddresses.Load();

                    #region addresses
                    //first set default addresses.
                    order.ShippingPostalAddressID = order.Customer.CurrAccDefault.PostalAddressID;
                    order.BillingPostalAddressID  = order.Customer.CurrAccDefault.PostalAddressID;

                    if (shippingPostalAddressID.HasValue)
                    {
                        var address = order.Customer.AllPostalAddresses.FirstOrDefault(x => x.PostalAddressID == shippingPostalAddressID.Value);
                        if (address != null)
                        {
                            order.ShippingPostalAddressID = address.PostalAddressID;
                        }
                    }

                    if (BillingPostalAddressID.HasValue)
                    {
                        var address = order.Customer.AllPostalAddresses.FirstOrDefault(x => x.PostalAddressID == BillingPostalAddressID.Value);
                        if (address != null)
                        {
                            order.BillingPostalAddressID = address.PostalAddressID;
                        }
                    }

                    #endregion addresses

                    // Optional
                    //order.ShipmentMethodCode = "1"; // ("1" means Immediate Delivery for ex.)
                    order.Description = description;//keep B2C order id

                    foreach (var item in items)
                    {
                        if (item.Rest != null && !string.IsNullOrWhiteSpace(item.Rest.Item1))
                        {
                            // via barcode
                            CreateRetailSaleOrderLineWithBarcode(order, item.Rest.Item1, item.Item5, item.Item6, item.Item7, null, currencyCode, discountNames);
                        }
                        else
                        {
                            //via combinations,variant
                            CreateRetailSaleOrderLineWithItemVariant(order, item.Item1, item.Item2, item.Item3, item.Item4, item.Item5, item.Item6, item.Item7, null, currencyCode, discountNames);
                        }
                    }

                    //shipment cost
                    if (shippingCost > 0)
                    {
                        CreateRetailSaleOrderExpense(order, _nebimIntegrationSettings.API_ShipmentExpenseProductCode, null, shippingCost, currencyCode);
                    }
                    //giftbox cost
                    if (giftBoxCost > 0)
                    {
                        CreateRetailSaleOrderExpense(order, _nebimIntegrationSettings.API_GiftboxExpenseProductCode, null, giftBoxCost, currencyCode);
                    }


                    //discounts to order total!
                    if (discountRate.HasValue)
                    {
                        ApplyDiscountRate(order, discountRate.Value); // % 30 iskonto
                    }
                    if (discountAmount.HasValue)
                    {
                        ApplyDiscountAmount(order, discountAmount.Value); // 20 TL iskonto
                    }
                    //TODO: ?
                    order.SaveAsCompleted();

                    //do not ship order it will be shipped after by another event (manual or scheduled automatically)
                    //this.CreateShipment(order);

                    sqlTrans.Commit();
                    return(order.OrderNumber);
                }
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
        }