Esempio n. 1
0
        private NebimV3.Shipments.RetailSale CreateRetailSaleShipment(NebimV3.Orders.RetailSale order, string description, DateTime?shipmentDate)
        {
            if (order == null)
            {
                throw new Exception("order can not be null for shipment");
            }
            if (!order.ExistsInDB())
            {
                throw new Exception("order does not exists for the shipment. order description:" + order.Description);
            }

            order.Load();
            NebimV3.Shipments.RetailSale shipment = new NebimV3.Shipments.RetailSale();

            // Required fields
            shipment.IsOrderBase   = true;
            shipment.ShippingDate  = shipmentDate.HasValue ? shipmentDate.Value : NebimV3.ApplicationCommon.V3Application.Context.Today;          // Or --> shipment.ShippingDate = new DateTime(2011, 12, 05)
            shipment.ShippingTime  = shipmentDate.HasValue ? shipmentDate.Value.TimeOfDay : NebimV3.ApplicationCommon.V3Application.Context.Time; // (Optional)
            shipment.OfficeCode    = _nebimIntegrationSettings.API_OfficeCode;
            shipment.WarehouseCode = _nebimIntegrationSettings.API_WarehouseCode;

            shipment.CustomerCode = order.CustomerCode;
            //shipment.Customer.CurrAccDefault.Load();
            shipment.ShippingPostalAddressID = order.ShippingPostalAddressID;
            shipment.BillingPostalAddressID  = order.BillingPostalAddressID;

            // Optional
            shipment.Description = description;

            return(shipment);
        }
Esempio n. 2
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;
     }
 }
Esempio n. 3
0
 private void ApplyDiscountAmount(NebimV3.Orders.RetailSale order, decimal discountAmount)
 {
     // amount discount is not supported so, do it by rate discount
     //    order.Summary.Calculate();
     //    order.Summary.SetTDiscountVI(1, discountAmount); // 1 sabit
     //    order.ApplySummary();
 }
Esempio n. 4
0
        private void CreateRetailSaleOrderExpense(NebimV3.Orders.RetailSale ST,
                                                  string itemCode,
                                                  decimal?discountIncludingTax,
                                                  decimal?priceIncludingTax,
                                                  string currencyCode
                                                  )
        {
            // Create a new line.
            NebimV3.Orders.RetailSaleLine line = (NebimV3.Orders.RetailSaleLine)(ST.TransactionFactory.CreateLine(ST));

            // Required
            //line.ItemTypeCode = (byte)(NebimV3.ApplicationCommon.ItemTypes.Expense);
            line.ItemTypeCode = (byte)(NebimV3.ApplicationCommon.ItemTypes.Product);
            line.ItemCode     = itemCode;
            line.ColorCode    = "";
            line.ItemDim1Code = "";
            line.ItemDim2Code = "";
            line.ItemDim3Code = "";
            line.Qty1         = 1;
            //line.CurrencyCode = currencyCode;
            line.ActualPriceCurrencyCode = currencyCode;

            if (priceIncludingTax.HasValue)
            {
                line.PriceVI = priceIncludingTax.Value; // kdv ddahil
            }
            line.Save();                                // Saving the first line of the transaction, also saves the transaction header.
        }
Esempio n. 5
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;
     }
 }
Esempio n. 6
0
        private void CreateRetailSaleOrderLineWithBarcode(NebimV3.Orders.RetailSale TW, string barcode, int quantity, decimal?discountIncludingTax,
                                                          decimal?priceIncludingTax, string description, string currencyCode, string discountNames)
        {
            // Create a new line.
            NebimV3.Orders.RetailSaleLine line = (NebimV3.Orders.RetailSaleLine)(TW.TransactionFactory.CreateLine(TW));

            // If you do not have any item variant info(ItemCode, ColorCode, Dim1Code, etc...)
            // But have a Barcode Number
            line.UsedBarcode             = barcode;
            line.Qty1                    = quantity;
            line.ActualPriceCurrencyCode = currencyCode;

            if (priceIncludingTax.HasValue)
            {
                line.PriceVI = priceIncludingTax.Value;// kdv ddahil
            }
            line.LineDescription = description;
            // Optional properties(LineDescription, DeliveryDate etc...) can be assigned also as described in previous method.
            line.Save();

            //save discount names(campaign names)
            if (_nebimIntegrationSettings.DiscountNameSavingEnabled && !string.IsNullOrWhiteSpace(discountNames))
            {
                foreach (var name in discountNames.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    SaveOrderDiscountOffer(Guid.Empty, TW.HeaderID, line.LineID, 0, 0, "1", name);
                }
            }
        }
Esempio n. 7
0
        // Elimizde yalnızca sipariş numarası var ise
        public void SavePayment(string orderNumber, myPaymentTypes paymentType, string creditCardTypeCode, byte installment, string maskedCCNo, string provisionNo)
        {
            NebimV3.Orders.RetailSale order = new NebimV3.Orders.RetailSale();
            order.OrderNumber = orderNumber;
            order.Load();

            this.SavePayment(order, paymentType, creditCardTypeCode, installment, maskedCCNo, provisionNo);
        }
Esempio n. 8
0
        private void CreateRetailSaleShipmentLinesFromOrderLines(NebimV3.Orders.RetailSale order, NebimV3.Shipments.RetailSale ST)
        {
            foreach (NebimV3.Orders.RetailSaleLine orderLine in order.Lines)
            {
                NebimV3.Shipments.RetailSaleLine line = (NebimV3.Shipments.RetailSaleLine)(ST.TransactionFactory.CreateLine(ST));

                // Required
                line.OrderLineID = orderLine.LineID;
                line.Qty1        = orderLine.Qty1; // Or may be less.
                line.ItemCode    = orderLine.ItemCode;
                // Optional
                line.LineDescription = orderLine.LineDescription;

                line.Save();
            }
        }
Esempio n. 9
0
        // This method demonstrates how to use "variant info" and other options.
        private void CreateRetailSaleOrderLineWithItemVariant(NebimV3.Orders.RetailSale ST,
                                                              string itemCode,
                                                              string colorCode,
                                                              string itemDim1Code,
                                                              string itemDim2Code,
                                                              int quantity,
                                                              decimal?discountIncludingTax,
                                                              decimal?priceIncludingTax,
                                                              string description,
                                                              string currencyCode,
                                                              string discountNames
                                                              )
        {
            // Create a new line.
            NebimV3.Orders.RetailSaleLine line = (NebimV3.Orders.RetailSaleLine)(ST.TransactionFactory.CreateLine(ST));

            // Required
            line.ItemTypeCode = (byte)(NebimV3.ApplicationCommon.ItemTypes.Product);
            line.ItemCode     = itemCode;
            line.ColorCode    = colorCode;
            line.ItemDim1Code = itemDim1Code;
            line.ItemDim2Code = itemDim2Code;
            line.ItemDim3Code = "";
            line.Qty1         = quantity;
            //line.CurrencyCode = currencyCode;
            line.ActualPriceCurrencyCode = currencyCode;


            if (priceIncludingTax.HasValue)
            {
                line.PriceVI = priceIncludingTax.Value;// kdv dahil
            }


            line.LineDescription = description;

            line.Save(); // Saving the first line of the transaction, also saves the transaction header.

            //save discount names(campaign names)
            if (_nebimIntegrationSettings.DiscountNameSavingEnabled && !string.IsNullOrWhiteSpace(discountNames))
            {
                foreach (var name in discountNames.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    SaveOrderDiscountOffer(Guid.Empty, ST.HeaderID, line.LineID, 0, 0, "1", name);
                }
            }
        }
Esempio n. 10
0
        private void SavePaymentByCreditCard(NebimV3.Orders.RetailSale order, string creditCardTypeCode, byte installment, string maskedCCNo, string provisionNo)
        {
            if (!order.Summary.Initialized)
            {
                order.Summary.Calculate();
            }

            NebimV3.Payments.CreditCardPayment ccTrans = new NebimV3.Payments.CreditCardPayment();


            ccTrans.CreditCardPaymentTypeCode = NebimV3.Payments.CreditCardPaymentTypes.SalePayment;
            ccTrans.PaymentDate       = order.OrderDate;
            ccTrans.PaymentTime       = order.OrderTime;
            ccTrans.OfficeCode        = order.OfficeCode;
            ccTrans.LocalCurrencyCode = order.LocalCurrencyCode;
            ccTrans.CurrAccTypeCode   = order.CurrAccTypeCode;
            ccTrans.CurrAccCode       = order.CustomerCode;
            ccTrans.DocCurrencyCode   = order.DocCurrencyCode;
            ccTrans.RefNumber         = order.OrderNumber;
            ccTrans.ApplicationCode   = NebimV3.v3Entities.ApplicationCodes.Order;
            ccTrans.StoreCode         = _nebimIntegrationSettings.API_StoreCode;

            var PaymentPlans = order.GetPaymentPlans();

            PaymentPlans.Load();
            ccTrans.ApplicationID = PaymentPlans[0].OrderPaymentPlanID;

            NebimV3.Payments.CreditCardPaymentLine line = new NebimV3.Payments.CreditCardPaymentLine(ccTrans);

            // Required
            line.CreditCardTypeCode         = creditCardTypeCode; // Kart Tipi
            line.CreditCardInstallmentCount = installment;        // Taksit sayısı - (PUAN için 0 taksit)
            line.DocCurrencyCode            = ccTrans.DocCurrencyCode;
            line.Amount = order.Summary.DebitNetAmount;

            // Optional
            line.CreditCardNum  = maskedCCNo; // Kart Numarası
            line.POSProvisionID = provisionNo;

            line.Save();

            ccTrans.SaveAsCompleted();
        }
Esempio n. 11
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;
     }
 }
Esempio n. 12
0
        private void SavePaymentByBank(NebimV3.Orders.RetailSale order)
        {
            if (!order.Summary.Initialized)
            {
                order.Summary.Calculate();
            }

            NebimV3.Banks.Bank bankTrans = new NebimV3.Banks.Bank();

            bankTrans.BankTransTypeCode = NebimV3.Banks.BankTransTypes.BankRemittance_EFT;
            bankTrans.DocumentDate      = order.OrderDate;
            bankTrans.DocumentTime      = order.OrderTime;
            bankTrans.OfficeCode        = order.OfficeCode;
            bankTrans.LocalCurrencyCode = order.LocalCurrencyCode;
            bankTrans.DocCurrencyCode   = order.DocCurrencyCode;
            bankTrans.RefNumber         = order.OrderNumber;
            bankTrans.StoreCode         = _nebimIntegrationSettings.API_StoreCode;

            bankTrans.ApplicationCode = NebimV3.v3Entities.ApplicationCodes.Order;
            var PaymentPlans = order.GetPaymentPlans();

            PaymentPlans.Load();
            bankTrans.ApplicationID = PaymentPlans[0].OrderPaymentPlanID;

            NebimV3.Banks.BankLine line = new NebimV3.Banks.BankLine(bankTrans);
            line.CurrAccTypeCode = order.CurrAccTypeCode;
            line.CurrAccCode     = order.CustomerCode;

            line.BankAccountCode = _nebimIntegrationSettings.API_BankAccountCode; // Havale yapılan banka hesabının Cari Hesap Kodu

            line.DocCurrencyCode = bankTrans.DocCurrencyCode;
            line.Amount          = order.Summary.DebitNetAmount;

            line.DueDate = DateTime.Now;

            line.Save();

            bankTrans.SaveAsCompleted();
        }
Esempio n. 13
0
        private void SavePaymentByCash(NebimV3.Orders.RetailSale order, string CashAccountCode)
        {
            if (!order.Summary.Initialized)
            {
                order.Summary.Calculate();
            }

            NebimV3.Cashs.Cash CashTrans = new NebimV3.Cashs.Cash();

            CashTrans.CashTransTypeCode = NebimV3.Cashs.CashTransTypes.PaymentsIn;
            CashTrans.DocumentDate      = order.OrderDate;
            CashTrans.DocumentTime      = order.OrderTime;
            CashTrans.OfficeCode        = order.OfficeCode;
            CashTrans.StoreCode         = order.StoreCode;
            CashTrans.CashAccountCode   = CashAccountCode;
            CashTrans.LocalCurrencyCode = order.LocalCurrencyCode;
            CashTrans.DocCurrencyCode   = order.DocCurrencyCode;
            CashTrans.RefNumber         = order.OrderNumber;

            CashTrans.ApplicationCode = NebimV3.v3Entities.ApplicationCodes.Order;

            var PaymentPlans = order.GetPaymentPlans();

            PaymentPlans.Load();
            CashTrans.ApplicationID = PaymentPlans[0].OrderPaymentPlanID;


            NebimV3.Cashs.CashLine line = new NebimV3.Cashs.CashLine(CashTrans);
            line.CurrAccTypeCode = order.CurrAccTypeCode;
            line.CurrAccCode     = order.CustomerCode;


            line.DocCurrencyCode = CashTrans.DocCurrencyCode;
            line.Amount          = order.Summary.DebitNetAmount;

            line.Save();

            CashTrans.SaveAsCompleted();
        }
Esempio n. 14
0
 private void ApplyDiscountRate(NebimV3.Orders.RetailSale order, double rate)
 {
     order.Summary.Calculate();
     order.Summary.SetTDisRate(2, rate); // 2 sabit
     order.ApplySummary();
 }
Esempio n. 15
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;
            }
        }