예제 #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
 //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;
     }
 }
예제 #3
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;
            }
        }