示例#1
0
        public async void TransfertTicket()
        {
            ticket.Client       = this.SelectedClient;
            ticket.MontantPaye += MontantRecu;

            if (ticket.Reste <= 0)
            {
                ticket.EstPaye = true;
            }


            Facture fac = new Facture();

            fac.EstDelivrer   = true;
            fac.Position      = ticket.Position;
            fac.Series        = settings.SeriesFacture;
            fac.EstPaye       = (MontantRetour >= 0);
            fac.Client        = SelectedClient?.Id;
            fac.NomClient     = SelectedClient?.NomComplet;
            fac.DateCreation  = DateTime.Now;
            fac.DateEcheance  = DateTime.Now;
            fac.Remarques     = $"{ticket.ticketType.ToString()} {ticket.Numero}";
            fac.VenteComptoir = true;
            fac.UpdateStock   = true;
            var repas = ticket.CarteLines;



            foreach (var item in repas)
            {
                LigneFacture line = item.article.Map("LigneFacture") as LigneFacture;
                line.PrixUnitaire = item.PricUnitaire;
                line.Qts          = item.Qts;
                fac.ArticleFacture.Add(line);
            }
            if (DeleteTicket && ticket.Reste > 0)
            {
                var response = MessageBox.Show("etes vous sur de vouloir supprimer le ticket partiellement payée?", "SUPPRIMER TICKET?", MessageBoxButton.YesNo);
                if (response == MessageBoxResult.No)
                {
                    return;
                }
            }
            if (CreateFacture && ticket.Reste > 0)
            {
                MessageBox.Show("Vous pouvez pas facturer une commande partiellement payée. Décocher <FACTURER>");
                return;
            }
            if (CreateFacture)
            {
                try
                {
                    //214 214


                    fac.RemiseGlobal  = ticket.Remise;
                    ticket.RefFacture = fac.Id;
                    if (settings.SeriesFacture != null && settings.SeriesFacture != ObjectId.Empty)
                    {
                        fac.Series = settings.SeriesFacture;
                    }

                    fac.Save();
                    fac.Submit();

                    //var paiement = fac.SaisirPaiement(false);
                    //paiement.Save();
                    //paiement.Submit();
                }
                catch (Exception s)
                {
                    MessageBox.Show(s.Message);
                }
            }
            if (PrintKitchen)
            {
            }
            if (PrintPdf)
            {
                var local = PosSettings.getInstance().POSPrinter;

                if (string.IsNullOrWhiteSpace(settings.NomTemplate))
                {
                    MessageBox.Show("Définis le modéle d'impression dans paramétres");
                    return;
                }
                var doc = fac.ExportWORD(fac.GetType(), settings.NomTemplate, !settings.DontUseHeader);
                try
                {
                    const string ESC             = "\u001B";
                    const string p               = "\u0070";
                    const string m               = "\u0000";
                    const string t1              = "\u0025";
                    const string t2              = "\u0250";
                    const string openTillCommand = ESC + p + m + t1 + t2;
                    RawPrinterHelper.SendStringToPrinter(local, openTillCommand);

                    ProcessStartInfo info = new ProcessStartInfo(doc);
                    info.Arguments      = "\"" + local + "\"";
                    info.Verb           = "Printto";
                    info.CreateNoWindow = true;
                    info.WindowStyle    = ProcessWindowStyle.Hidden;
                    Process.Start(info);
                }
                catch (Exception s)
                {
                    MessageBox.Show(s.Message);
                }
            }
            if (OpenPdf)
            {
                await DataHelpers.Shell.OpenScreenDetach(fac, fac.Name);
            }

            if (DeleteTicket)
            {
                this.RequestClose(true);
            }
            else
            {
                this.RequestClose(false);
            }
        }