Ejemplo n.º 1
0
        public void SaveReductionTypeFromDateToDate(PsSpecificPrice Obj)
        {
            /*
             * String TxtSQL = "update ps_specific_price set reduction_type = '" + Obj.ReductionType + "' where id_specific_price = " + Obj.IDSpecificPrice;
             * this.DBPrestashop.ExecuteCommand(TxtSQL);
             * TxtSQL = "update ps_specific_price set ps_specific_price.from = '0000-00-00 00:00:00' where id_specific_price = " + Obj.IDSpecificPrice;
             * this.DBPrestashop.ExecuteCommand(TxtSQL);
             * TxtSQL = "update ps_specific_price set ps_specific_price.to = '0000-00-00 00:00:00 ' where id_specific_price = " + Obj.IDSpecificPrice;
             * this.DBPrestashop.ExecuteCommand(TxtSQL);
             * this.Save();
             */
            String TxtSQL = "update ps_specific_price "
                            + " set ps_specific_price.reduction_type = '" + Obj.ReductionType + "', "
                            + " ps_specific_price.from = '0000-00-00 00:00:00', "
                            + " ps_specific_price.to = '0000-00-00 00:00:00' "
                            + " where id_specific_price = " + Obj.IDSpecificPrice;

            this.DBPrestashop.ExecuteCommand(TxtSQL);
        }
Ejemplo n.º 2
0
        public void Exec(int DocumentSend)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Sage.F_DOCENTETERepository F_DOCENTETERepository = new Model.Sage.F_DOCENTETERepository();
                Model.Sage.F_DOCENTETE           F_DOCENTETE           = F_DOCENTETERepository.Read(DocumentSend);

                Model.Local.OrderRepository OrderRepository = new Model.Local.OrderRepository();
                int PreID;
                // Contrôle de la provenance Web de la commande via une synchro Prestaconnect
                if (int.TryParse(F_DOCENTETE.DO_NoWeb, out PreID) &&
                    OrderRepository.ExistPrestashop(PreID))
                {
                    Model.Prestashop.PsOrdersRepository PsOrdersRepository = new Model.Prestashop.PsOrdersRepository();
                    if (PsOrdersRepository.ExistOrder(PreID))
                    {
                        Model.Prestashop.PsCartPreOrderRepository PsCartPreOrderRepository = new Model.Prestashop.PsCartPreOrderRepository();
                        if (!PsCartPreOrderRepository.ExistOrder(PreID))
                        {
                            Model.Prestashop.PsOrders PsOrder = PsOrdersRepository.ReadOrder(PreID);

                            Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
                            if (PsCustomerRepository.ExistCustomer(PsOrder.IDCustomer))
                            {
                                // récupération montant total des lignes
                                decimal?total_document = new Model.Sage.F_DOCLIGNERepository().MontantDomaineTypePieceValorise(F_DOCENTETE.DO_Domaine.Value, F_DOCENTETE.DO_Type.Value, F_DOCENTETE.DO_Piece);
                                // ajout frais de port pied de document
                                decimal total_port = 0;
                                if (F_DOCENTETE.DO_ValFrais != null)
                                {
                                    if (F_DOCENTETE.DO_TypeLigneFrais == (short)ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_TypeLigne.TTC)
                                    {
                                        total_port = (decimal)F_DOCENTETE.DO_ValFrais;
                                    }
                                    else
                                    {
                                        total_port = (decimal)F_DOCENTETE.DO_ValFrais * (1 + (F_DOCENTETE.DO_Taxe1.Value / 100));
                                    }
                                }
                                // calcul des acomptes et règlements
                                decimal?total_reglements = new Model.Sage.F_DOCREGLRepository().MontantDomaineTypePiece(F_DOCENTETE.DO_Domaine.Value, F_DOCENTETE.DO_Type.Value, F_DOCENTETE.DO_Piece);
                                if (total_document != null && total_reglements != null)
                                {
                                    decimal solde = (decimal)((total_document + total_port) - total_reglements);
                                    if (solde > 0)
                                    {
                                        #region création nouveau panier
                                        Model.Prestashop.PsCartRepository PsCartRepository = new Model.Prestashop.PsCartRepository();
                                        Model.Prestashop.PsCart           PsCart           = new Model.Prestashop.PsCart()
                                        {
                                            DateAdd           = DateTime.Now,
                                            DateUpd           = DateTime.Now,
                                            DeliveryOption    = string.Empty,
                                            Gift              = 0,
                                            GiftMessage       = string.Empty,
                                            IDAddressDelivery = PsOrder.IDAddressDelivery,
                                            IDAddressInvoice  = PsOrder.IDAddressInvoice,
                                            IDCarrier         = 0,
                                            IDCurrency        = PsOrder.IDCurrency,
                                            IDCustomer        = PsOrder.IDCustomer,
                                            IDGuest           = 0,
                                            IDLang            = PsOrder.IDLang,
                                            IDShop            = PsOrder.IDShop,
                                            IDShopGroup       = PsOrder.IDShopGroup,
                                            Recyclable        = PsOrder.Recyclable,
                                            SecureKey         = PsOrder.SecureKey,
                                        };
                                        PsCartRepository.Add(PsCart);
                                        #endregion

                                        #region attribution du solde en tant que prix spécifique pour le produit
                                        Model.Prestashop.PsSpecificPriceRepository PsSpecificPriceRepository = new Model.Prestashop.PsSpecificPriceRepository();
                                        Model.Prestashop.PsSpecificPrice           PsSpecificPrice           = new Model.Prestashop.PsSpecificPrice()
                                        {
                                            IDProduct     = (uint)Core.Global.GetConfig().ModulePreorderPrestashopProduct,
                                            FromQuantity  = 1,
                                            IDCart        = PsCart.IDCart,
                                            IDCustomer    = PsCart.IDCustomer,
                                            Price         = solde,
                                            ReductionType = Model.Prestashop.PsSpecificPrice._ReductionType_Amount,
                                            From          = new DateTime(),
                                            To            = new DateTime(),
                                        };
                                        PsSpecificPriceRepository.Add(PsSpecificPrice);
                                        PsSpecificPriceRepository.SaveReductionTypeFromDateToDate(PsSpecificPrice);
                                        #endregion

                                        #region attribution de l'article au panier
                                        Model.Prestashop.PsCartProductRepository PsCartProductRepository = new Model.Prestashop.PsCartProductRepository();
                                        Model.Prestashop.PsCartProduct           PsCartProduct           = new Model.Prestashop.PsCartProduct()
                                        {
                                            DateAdd            = DateTime.Now,
                                            IDAddressDelivery  = PsCart.IDAddressDelivery,
                                            IDCart             = PsCart.IDCart,
                                            IDProduct          = (uint)Core.Global.GetConfig().ModulePreorderPrestashopProduct,
                                            IDProductAttribute = 0,
                                            IDShop             = PsCart.IDShop,
                                            Quantity           = 1,
                                        };
                                        PsCartProductRepository.Add(PsCartProduct);
                                        #endregion

                                        #region ajout de l'identification du panier en tant que solde de précommande
                                        Model.Prestashop.PsCartPreOrder PsCartPreorder = new Model.Prestashop.PsCartPreOrder()
                                        {
                                            IDCart     = PsCart.IDCart,
                                            IDPreOrder = PsOrder.IDOrder,
                                        };
                                        PsCartPreOrderRepository.Add(PsCartPreorder);
                                        #endregion

                                        // génération URL directe panier
                                        PsOrder.Cart_URL = Core.Global.URL_Prestashop + "/commande?step=1&recover_cart=" + PsCart.IDCart
                                                           + "&token_cart=" + Core.RandomString.HashMD5(Core.Global.GetConfig().TransfertPrestashopCookieKey + "recover_cart_" + PsCart.IDCart.ToString());

                                        Core.Sync.SynchronisationCommande.SendMail(33, PsOrder);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }

            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
Ejemplo n.º 3
0
 public void Add(PsSpecificPrice Obj)
 {
     this.DBPrestashop.PsSpecificPrice.InsertOnSubmit(Obj);
     this.Save();
 }