private void PostProduction(ProductionOrder dbOrder)
        {
            CWInvPosting invpostingDialog = new CWInvPosting(api, "ReportAsFinished", true);

#if !SILVERLIGHT
            invpostingDialog.DialogTableId = 2000000041;
#endif
            invpostingDialog.Closed += async delegate
            {
                if (invpostingDialog.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var papi          = new Uniconta.API.Inventory.ProductionAPI(api);
                    var postingResult = await papi.ReportAsFinished(dbOrder, invpostingDialog.Date, invpostingDialog.Text, invpostingDialog.TransType,
                                                                    invpostingDialog.Comment, invpostingDialog.FixedVoucher, invpostingDialog.Simulation, new GLTransClientTotal(), 0, invpostingDialog.NumberSeries);

                    busyIndicator.IsBusy      = false;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("LoadingMsg");
                    if (postingResult == null)
                    {
                        return;
                    }
                    if (postingResult.Err != ErrorCodes.Succes)
                    {
                        Utility.ShowJournalError(postingResult, dgProductionOrders, goToLinesMsg: false);
                    }
                    else if (invpostingDialog.Simulation)
                    {
                        if (postingResult.SimulatedTrans != null)
                        {
                            AddDockItem(TabControls.SimulatedTransactions, postingResult.SimulatedTrans, Uniconta.ClientTools.Localization.lookup("SimulatedTransactions"), null, true);
                        }
                        else
                        {
                            var msg = string.Format(Uniconta.ClientTools.Localization.lookup("OBJisEmpty"), Uniconta.ClientTools.Localization.lookup("LedgerTransList"));
                            msg = Uniconta.ClientTools.Localization.lookup("JournalOK") + Environment.NewLine + msg;
                            UnicontaMessageBox.Show(msg, Uniconta.ClientTools.Localization.lookup("Message"));
                        }
                    }
                    else
                    {
                        dgProductionOrders.UpdateItemSource(3, dbOrder);

                        string msg;
                        if (postingResult.JournalPostedlId != 0)
                        {
                            msg = string.Format("{0} {1}={2}", Uniconta.ClientTools.Localization.lookup("JournalHasBeenPosted"), Uniconta.ClientTools.Localization.lookup("JournalPostedId"), postingResult.JournalPostedlId);
                        }
                        else
                        {
                            msg = Uniconta.ClientTools.Localization.lookup("JournalHasBeenPosted");
                        }
                        UnicontaMessageBox.Show(msg, Uniconta.ClientTools.Localization.lookup("Message"));
                    }
                }
            };
            invpostingDialog.Show();
        }
        void PostJournal()
        {
            api.AllowBackgroundCrud = false;
            var savetask = saveGrid();

            api.AllowBackgroundCrud = true;

            var lines         = dgInvJournalLine.ItemsSource as IList;
            int NumberOfLines = lines.Count;

            if (NumberOfLines == 0)
            {
                return;
            }

            CWInvPosting invpostingDialog = new CWInvPosting(api);

            invpostingDialog.showCompanyName = true;
#if !SILVERLIGHT
            invpostingDialog.DialogTableId = 2000000039;
#endif
            invpostingDialog.Closed += async delegate
            {
                if (invpostingDialog.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    if (savetask != null)
                    {
                        await savetask;
                    }
                    var postingApi    = new Uniconta.API.Inventory.PostingAPI(api);
                    var postingResult = await postingApi.PostJournal(journal, invpostingDialog.Date, invpostingDialog.Text, invpostingDialog.TransType, invpostingDialog.Comment, invpostingDialog.FixedVoucher, invpostingDialog.Simulation, new GLTransClientTotal(), NumberOfLines);

                    busyIndicator.IsBusy      = false;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("LoadingMsg");

                    if (postingResult == null)
                    {
                        return;
                    }

                    if (postingResult.Err != ErrorCodes.Succes)
                    {
                        Utility.ShowJournalError(postingResult, dgInvJournalLine);
                    }

                    else if (invpostingDialog.Simulation)
                    {
                        if (postingResult.SimulatedTrans != null)
                        {
                            AddDockItem(TabControls.SimulatedTransactions, postingResult.SimulatedTrans, Uniconta.ClientTools.Localization.lookup("SimulatedTransactions"), null, true);
                        }
                        else
                        {
                            var msg = string.Format(Uniconta.ClientTools.Localization.lookup("OBJisEmpty"), Uniconta.ClientTools.Localization.lookup("LedgerTransList"));
                            msg = Uniconta.ClientTools.Localization.lookup("JournalOK") + Environment.NewLine + msg;
                            UnicontaMessageBox.Show(msg, Uniconta.ClientTools.Localization.lookup("Message"));
                        }
                    }
                    else
                    {
                        string msg;
                        if (postingResult.JournalPostedlId != 0)
                        {
                            msg = string.Format("{0} {1}={2}", Uniconta.ClientTools.Localization.lookup("JournalHasBeenPosted"), Uniconta.ClientTools.Localization.lookup("JournalPostedId"), postingResult.JournalPostedlId);
                        }
                        else
                        {
                            msg = Uniconta.ClientTools.Localization.lookup("JournalHasBeenPosted");
                        }
                        UnicontaMessageBox.Show(msg, Uniconta.ClientTools.Localization.lookup("Message"));

                        if (journal._DeleteLines)
                        {
                            dgInvJournalLine.ItemsSource = new List <InvJournalLineGridClient>();
                        }
                    }
                }
            };
            invpostingDialog.Show();
        }