Пример #1
0
        void PostProjectOrder(DebtorOrderClient order)
        {
            var dialog = new CwPostProjectOrder();

            dialog.DialogTableId = 2000000087;
            dialog.Closed       += async delegate
            {
                if (dialog.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var invApi        = new Uniconta.API.DebtorCreditor.InvoiceAPI(api);
                    var postingResult = await invApi.PostProjectOrder(order, null, dialog.Date, dialog.Simulation, new GLTransClientTotal(), null, dialog.PostOnlyDelivered);

                    busyIndicator.IsBusy      = false;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("LoadingMsg");
                    var ledgerRes = postingResult.ledgerRes;
                    if (ledgerRes == null)
                    {
                        return;
                    }
                    if (ledgerRes.Err != ErrorCodes.Succes)
                    {
                        Utility.ShowJournalError(ledgerRes, dgMultiInvGrid, false);
                    }
                    else if (dialog.Simulation && ledgerRes.SimulatedTrans != null && ledgerRes.SimulatedTrans.Length > 0)
                    {
                        AddDockItem(TabControls.SimulatedTransactions, ledgerRes.SimulatedTrans, Uniconta.ClientTools.Localization.lookup("SimulatedTransactions"), null, true);
                    }
                    else
                    {
                        string msg;
                        if (ledgerRes.JournalPostedlId != 0)
                        {
                            msg = string.Format("{0} {1}={2}", Uniconta.ClientTools.Localization.lookup("JournalHasBeenPosted"), Uniconta.ClientTools.Localization.lookup("JournalPostedId"), ledgerRes.JournalPostedlId);
                        }
                        else
                        {
                            msg = Uniconta.ClientTools.Localization.lookup("JournalHasBeenPosted");
                        }
                        UnicontaMessageBox.Show(msg, Uniconta.ClientTools.Localization.lookup("Message"));
                    }
                }
            };
            dialog.Show();
        }
        public static async void GenerateOIOXml(CrudAPI api, DCInvoice inv)
        {
            var Comp     = api.CompanyEntity;
            var InvCache = api.GetCache(typeof(Uniconta.DataModel.InvItem)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvItem));

            var VatCache = api.GetCache(typeof(Uniconta.DataModel.GLVat)) ?? await api.LoadCache(typeof(Uniconta.DataModel.GLVat));

            //SystemInfo.Visible = true;

            int            countErr   = 0;
            SaveFileDialog saveDialog = null;

            Uniconta.API.DebtorCreditor.InvoiceAPI Invapi = new Uniconta.API.DebtorCreditor.InvoiceAPI(api);

            var listPropval = new List <PropValuePair>()
            {
                PropValuePair.GenereteWhereElements("InvoiceNumber", inv._InvoiceNumber, CompareOperator.Equal),
                PropValuePair.GenereteWhereElements("DCAccount", inv._DCAccount, CompareOperator.Equal),
                PropValuePair.GenereteWhereElements("Date", inv._Date, CompareOperator.Equal)
            };

            var FindDebInvLocal = await api.Query <DebtorInvoiceClient>(listPropval);

            var invClient = FindDebInvLocal.FirstOrDefault();

            if (invClient == null)
            {
                return;
            }

            var Debcache = Comp.GetCache(typeof(Debtor)) ?? await api.LoadCache(typeof(Debtor));

            var debtor = (Debtor)Debcache.Get(invClient._DCAccount);

            if (debtor == null || !debtor._InvoiceInXML || invClient.SendTimeOIO != DateTime.MinValue)
            {
                if (!debtor._InvoiceInXML)
                {
                    UnicontaMessageBox.Show("Faktura i OIOUBL er ikke sat til denne debitor", Uniconta.ClientTools.Localization.lookup("Warning"));
                }
                return;
            }

            var InvTransInvoiceLines = (DebtorInvoiceLines[])await Invapi.GetInvoiceLines(invClient, new DebtorInvoiceLines()); //TODO:Test fakturering

            var layoutGroupCache = api.GetCache(typeof(DebtorLayoutGroup)) ?? await api.LoadCache(typeof(DebtorLayoutGroup));

            Contact contactPerson = null;

            if (invClient._ContactRef != 0)
            {
                var Contacts = api.GetCache(typeof(Uniconta.DataModel.Contact)) ?? await api.LoadCache(typeof(Uniconta.DataModel.Contact));

                foreach (var contact in (Uniconta.DataModel.Contact[])Contacts.GetRecords)
                {
                    if (contact.RowId == invClient._ContactRef)
                    {
                        contactPerson = contact;
                        break;
                    }
                }
            }

            DebtorOrders.SetDeliveryAdress(invClient, debtor, api);

            Debtor deliveryAccount;

            if (invClient._DeliveryAccount != null)
            {
                deliveryAccount = (Debtor)Debcache.Get(invClient._DeliveryAccount);
            }
            else
            {
                deliveryAccount = null;
            }

            WorkInstallation workInstallation = null;

            if (invClient._Installation != null)
            {
                var workInstallCache = api.GetCache(typeof(Uniconta.DataModel.WorkInstallation)) ?? await api.LoadCache(typeof(Uniconta.DataModel.WorkInstallation));

                workInstallation = (WorkInstallation)workInstallCache.Get(invClient._Installation);
            }

            CreationResult result;

            if (Comp._CountryId == CountryCode.Norway || Comp._CountryId == CountryCode.Netherlands)
            {
                result = EHF.GenerateEHFXML(Comp, debtor, deliveryAccount, invClient, InvTransInvoiceLines, InvCache, VatCache, null, contactPerson);
            }
            else
            {
                var attachments = await FromXSDFile.OIOUBL.ExportImport.Attachments.CollectInvoiceAttachments(invClient, api);

                result = Uniconta.API.DebtorCreditor.OIOUBL.GenerateOioXML(Comp, debtor, deliveryAccount, invClient, InvTransInvoiceLines, InvCache, VatCache, null, contactPerson, attachments, layoutGroupCache, workInstallation);
            }

            bool createXmlFile = true;

            var errorInfo = "";

            if (result.HasErrors)
            {
                countErr++;
                createXmlFile = false;

                foreach (FromXSDFile.OIOUBL.ExportImport.PrecheckError error in result.PrecheckErrors)
                {
                    errorInfo += error.ToString() + "\n";
                }
            }

            if (result.Document != null && createXmlFile)
            {
                string invoice = Uniconta.ClientTools.Localization.lookup("Invoice");
                saveDialog          = Uniconta.ClientTools.Util.UtilDisplay.LoadSaveFileDialog;
                saveDialog.FileName = string.Format("{0}_{1}", invoice, invClient.InvoiceNumber);
                saveDialog.Filter   = "XML-File | *.xml";
                bool?dialogResult = saveDialog.ShowDialog();
                if (dialogResult != true)
                {
                    return;
                }

                var filename = saveDialog.FileName;

                result.Document.Save(filename);
                await Invapi.MarkSendInvoiceOIO(invClient);

                invClient.SendTimeOIO = BasePage.GetSystemDefaultDate();
            }

            //invClient.NotifySystemInfoSet();

            //if (countErr != 0)
            //    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup(String.Format("Couldn't create file for {0} invoice(s). Please check System info column.", countErr)));

            if (countErr != 0 && !string.IsNullOrWhiteSpace(errorInfo))
            {
                UnicontaMessageBox.Show(errorInfo, Uniconta.ClientTools.Localization.lookup("Error"));
            }
        }