private void JoinAllOrdersToSelectedItem(CreditorOrderClient selectedItem, IEnumerable <CreditorOrderClient> allOrderList)
        {
            EraseYearWindow EraseYearWindowDialog = new EraseYearWindow("", true);

            EraseYearWindowDialog.Closed += async delegate
            {
                if (EraseYearWindowDialog.DialogResult == true)
                {
                    var        ordersApi = new OrderAPI(api);
                    List <int> errors    = new List <int>();
                    foreach (var order in allOrderList)
                    {
                        if (order.OrderNumber == selectedItem.OrderNumber)
                        {
                            continue;
                        }
                        var result = await ordersApi.JoinTwoOrders(order, selectedItem);

                        if (result != Uniconta.Common.ErrorCodes.Succes)
                        {
                            errors.Add(order.OrderNumber);
                        }
                    }
                    if (errors.Count > 0)
                    {
                        var failedOrderNumbers = string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup("OrderNumber"), string.Join(",", errors));
                        var message            = string.Format(Uniconta.ClientTools.Localization.lookup("FailedJoinOBJ"), failedOrderNumbers, selectedItem.OrderNumber);
                        UnicontaMessageBox.Show(message, Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                    }
                    var propValpair = Uniconta.Common.PropValuePair.GenereteWhereElements("OrderNumber", typeof(int), selectedItem.OrderNumber.ToString());
                    await dgJoinMultiPurchaseGrid.Filter(new List <Uniconta.Common.PropValuePair>() { propValpair });
                }
            };
            EraseYearWindowDialog.Show();
        }
예제 #2
0
        public void InsertKøbsOrder(MimeMessage message, int DocumentRef, clsParam objParam)
        {
            var From = message.From.ToString();

            From = ExtractEmails(From);
            var Date    = message.Date.DateTime;
            var Subject = objParam.Tekst;

            if (string.IsNullOrEmpty(Subject))
            {
                Subject = message.Subject;
            }


            string wAccount = null;

            try
            {
                wAccount = (from c in this.m_Creditors where c.Account == objParam.Konto select c.Account).First();
            }
            catch (Exception)
            {
                try
                {
                    wAccount = (from c in this.m_Creditors where ((c.ContactEmail != null) && (c.ContactEmail.ToLower() == From.ToLower())) || ((c._InvoiceEmail != null) && (c._InvoiceEmail.ToLower() == From.ToLower())) select c.Account).First();
                }
                catch
                {
                    wAccount = "100000"; //Ukendt kreditor
                }
            }

            CreditorOrderClient recOrder = new CreditorOrderClient()
            {
                Account      = wAccount,
                InvoiceDate  = Date,
                DeliveryDate = Date,
                DocumentRef  = DocumentRef,
                DeleteLines  = true,
                DeleteOrder  = true
            };
            var taskInsertCreditorOrder = m_api.Insert(recOrder);

            taskInsertCreditorOrder.Wait();
            var err1 = taskInsertCreditorOrder.Result;

            CreditorOrderLineClient recOrderLine = new CreditorOrderLineClient()
            {
                Text           = Subject,
                Qty            = 1,
                Price          = objParam.Kredit == null ? 0 : (double)objParam.Kredit,
                PostingAccount = objParam.Modkonto,
            };

            recOrderLine.SetMaster(recOrder);
            var taskInsertCreditorOrderLine = m_api.Insert(recOrderLine);

            taskInsertCreditorOrderLine.Wait();
            var err2 = taskInsertCreditorOrderLine.Result;
        }
예제 #3
0
        private void AddVoucher(CreditorOrderClient selectedItem, string actionType)
        {
            var voucher = new VouchersClient();

            voucher._Content         = ContentTypes.PurchaseInvoice;
            voucher._PurchaseNumber  = selectedItem._OrderNumber;
            voucher._Project         = selectedItem._Project;
            voucher._Approver1       = selectedItem._Approver;
            voucher._CreditorAccount = selectedItem._InvoiceAccount ?? selectedItem._DCAccount;
#if !SILVERLIGHT
            if (actionType == "DragDrop")
            {
                var dragDropWindow = new UnicontaDragDropWindow(false);
                dragDropWindow.Closed += delegate
                {
                    if (dragDropWindow.DialogResult == true)
                    {
                        var fileInfo = dragDropWindow.FileInfoList?.SingleOrDefault();
                        if (fileInfo != null)
                        {
                            voucher._Data          = fileInfo.FileBytes;
                            voucher._Text          = fileInfo.FileName;
                            voucher._Fileextension = DocumentConvert.GetDocumentType(fileInfo.FileExtension);
                        }
                        Utility.ImportVoucher(selectedItem, api, voucher, true);
                    }
                };
                dragDropWindow.Show();
            }
            else
#endif
            Utility.ImportVoucher(selectedItem, api, voucher, false);
        }
예제 #4
0
        private void InitPage()
        {
            InitializeComponent();
            var Comp = api.CompanyEntity;

            CompCurrency = (byte)Comp._CurrencyId;

            ((TableView)dgCreditorOrderLineGrid.View).RowStyle = Application.Current.Resources["StyleRow"] as Style;
            ledim1.api        = ledim2.api = ledim3.api = ledim4.api = ledim5.api = LeAccount.api =
                lePayment.api = leTransType.api = LePostingAccount.api = leShipment.api = leDeliveryTerm.api =
                    Projectlookupeditor.api = PrCategorylookupeditor.api = employeelookupeditor.api = api;

            initialOrder = new CreditorOrderClient();
            initialOrder._DeliveryCountry = Comp._CountryId;
            initialOrder.SetMaster(Comp);

            setDimensions();
            cbDeliveryCountry.ItemsSource = Enum.GetValues(typeof(Uniconta.Common.CountryCode));
            SetRibbonControl(localMenu, dgCreditorOrderLineGrid);
            dgCreditorOrderLineGrid.api           = api;
            dgCreditorOrderLineGrid.BusyIndicator = busyIndicator;
            localMenu.OnItemClicked += localMenu_OnItemClicked;
            dgCreditorOrderLineGrid.View.DataControl.CurrentItemChanged += DataControl_CurrentItemChanged;
#if !SILVERLIGHT
            btnAccount.ToolTip = string.Format(Uniconta.ClientTools.Localization.lookup("CreateOBJ"), Uniconta.ClientTools.Localization.lookup("Creditor"));
#endif
            txtName.IsEnabled = false;
            dgCreditorOrderLineGrid.Visibility = Visibility.Visible;
            ShowCustomCloseConfiramtion        = true;

            // we setup first order
            ClearFields(initialOrder);

            if (dgCreditorOrderLineGrid.IsLoadedFromLayoutSaved)
            {
                dgCreditorOrderLineGrid.ClearSorting();
                dgCreditorOrderLineGrid.IsLoadedFromLayoutSaved = false;
            }

            this.creditors = Comp.GetCache(typeof(Uniconta.DataModel.Creditor));
            this.items     = Comp.GetCache(typeof(InvItem));
            if (Comp.Warehouse)
            {
                this.warehouse = Comp.GetCache(typeof(InvWarehouse));
            }
            if (Comp.ItemVariants)
            {
                this.variants1        = Comp.GetCache(typeof(InvVariant1));
                this.variants2        = Comp.GetCache(typeof(InvVariant2));
                this.standardVariants = Comp.GetCache(typeof(InvStandardVariant));
            }
            RemoveMenuItem();
            dgCreditorOrderLineGrid.allowSave = false;
#if SILVERLIGHT
            Application.Current.RootVisual.KeyDown += Page_KeyDown;
#else
            this.KeyDown += Page_KeyDown;
#endif
        }
        void InitPage(CrudAPI crudapi)
        {
            BusyIndicator        = busyIndicator;
            dAddress.Header      = Uniconta.ClientTools.Localization.lookup("DeliveryAddr");
            layoutControl        = layoutItems;
            lePostingAccount.api = Employeelookupeditor.api = leAccount.api = lePayment.api = cmbDim1.api
                                                                                                  = leTransType.api = cmbDim2.api = cmbDim3.api = cmbDim4.api = cmbDim5.api = leGroup.api = leShipment.api =
                                                                                                        PrCategorylookupeditor.api     = Projectlookupeditor.api = leApprover.api = leDeliveryTerm.api = leInvoiceAccount.api =
                                                                                                            PriceListlookupeditior.api = leLayoutGroup.api = leVat.api = prTasklookupeditor.api = crudapi;

#if SILVERLIGHT
            leRelatedOrder.api = crudapi;
#else
            leRelatedOrder.CrudApi = crudapi;
#endif

            cbDeliveryCountry.ItemsSource = Enum.GetValues(typeof(Uniconta.Common.CountryCode));
            if (editrow == null)
            {
                frmRibbon.DisableButtons("Delete");
                liCreatedTime.Visibility = Visibility.Collapsed;
                editrow          = CreateNew() as CreditorOrderClient;
                editrow._Created = DateTime.MinValue;
                if (Creditor != null)
                {
                    editrow.SetMaster(this.Creditor);
                    if (editrow.RowId == 0)
                    {
                        SetValuesFromMaster(this.Creditor);
                    }
                    leAccount.IsEnabled = txtName.IsEnabled = false;
                }
                if (Contact != null)
                {
                    editrow.SetMaster(Contact);
                    leAccount.IsEnabled = txtName.IsEnabled = cmbContactName.IsEnabled = false;
                }
            }
            else
            {
                BindContact(editrow.Creditor);
            }
            AdjustLayout();

            layoutItems.DataContext  = editrow;
            frmRibbon.OnItemClicked += frmRibbon_OnItemClicked;

            AcItem.ButtonClicked += AcItem_ButtonClicked;
#if !SILVERLIGHT
            editrow.PropertyChanged += Editrow_PropertyChanged;
#endif
            if (crudapi.GetCache(typeof(Uniconta.DataModel.Creditor)) == null)
            {
                crudapi.LoadCache(typeof(Uniconta.DataModel.Creditor));
            }
        }
예제 #6
0
        private InvoicePostingPrintGenerator SetupInvoicePostingPrintGenerator(CreditorOrderClient crOrder, IEnumerable <DCOrderLineClient> lines, DateTime generateDate, string invoiceNumber, bool isSimulated, bool showInvoice,
                                                                               bool postOnlyDelivered, bool isQuickPrint, int printPageCount, bool sendInvoiceByEmail, bool sendInvoiceByOutlook, bool sendOnlyToEmail, string SendOnlyEmailList, List <TableAddOnData> documents)
        {
            var invoicePostingResult = new InvoicePostingPrintGenerator(api, this);

            invoicePostingResult.SetUpInvoicePosting(crOrder, lines, CompanyLayoutType.PurchaseInvoice, generateDate, invoiceNumber, isSimulated, showInvoice,
                                                     postOnlyDelivered, isQuickPrint, printPageCount, sendInvoiceByEmail, sendInvoiceByOutlook, sendOnlyToEmail, SendOnlyEmailList, false, documents, false);

            return(invoicePostingResult);
        }
예제 #7
0
 void ClearFields(CreditorOrderClient initialOrder)
 {
     Order = StreamingManager.Clone(initialOrder) as CreditorOrderClient;
     Order.PropertyChanged += Editrow_PropertyChanged;
     this.DataContext       = Order;
     dgCreditorOrderLineGrid.UpdateMaster(Order);
     dgCreditorOrderLineGrid.ItemsSource = null;
     dgCreditorOrderLineGrid.AddFirstRow();
     LeAccount.Focus();
 }
예제 #8
0
        async void UpdateVoucher(CreditorOrderClient selectedItem)
        {
            busyIndicator.IsBusy = true;
            var err = await api.Update(selectedItem);

            busyIndicator.IsBusy = false;
            if (err != ErrorCodes.Succes)
            {
                UtilDisplay.ShowErrorCode(err);
            }
        }
예제 #9
0
        private void GenerateInvoice(CreditorOrderClient creditorOrderClient)
        {
            var  accountName     = string.Format("{0} ({1})", creditorOrderClient._DCAccount, creditorOrderClient.Name);
            var  creditor        = ClientHelper.GetRef(creditorOrderClient.CompanyId, typeof(Uniconta.DataModel.Creditor), creditorOrderClient._DCAccount) as Uniconta.DataModel.Creditor;
            bool showSendByEmail = creditor != null ? (!string.IsNullOrEmpty(creditor._InvoiceEmail) || creditor._EmailDocuments) : false;

            CWGenerateInvoice GenrateInvoiceDialog = new CWGenerateInvoice(true, string.Empty, true, true, showNoEmailMsg: !showSendByEmail, AccountName: accountName);

#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000002;
#endif
            GenrateInvoiceDialog.SetSendAsEmailCheck(false);
            GenrateInvoiceDialog.SetInvoiceNumber(creditorOrderClient._InvoiceNumber);
            if (creditorOrderClient._InvoiceDate != DateTime.MinValue)
            {
                GenrateInvoiceDialog.SetInvoiceDate(creditorOrderClient._InvoiceDate);
            }
            var additionalOrdersList = Utility.GetAdditionalOrders(api, creditorOrderClient);
            if (additionalOrdersList != null)
            {
                GenrateInvoiceDialog.SetAdditionalOrders(additionalOrdersList);
            }

            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    var isSimulated          = GenrateInvoiceDialog.IsSimulation;
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this);
                    invoicePostingResult.SetUpInvoicePosting(creditorOrderClient, null, CompanyLayoutType.PurchaseInvoice, GenrateInvoiceDialog.GenrateDate, GenrateInvoiceDialog.InvoiceNumber, isSimulated,
                                                             GenrateInvoiceDialog.ShowInvoice, false, GenrateInvoiceDialog.InvoiceQuickPrint, GenrateInvoiceDialog.NumberOfPages, GenrateInvoiceDialog.SendByEmail, !isSimulated && GenrateInvoiceDialog.SendByOutlook,
                                                             GenrateInvoiceDialog.sendOnlyToThisEmail, GenrateInvoiceDialog.Emails, false, null, false);
                    invoicePostingResult.SetAdditionalOrders(GenrateInvoiceDialog.AdditionalOrders?.Cast <DCOrder>().ToList());
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        if (invoicePostingResult.PostingResult.OrderDeleted)
                        {
                            dgCreditorOrdersGrid.UpdateItemSource(3, dgCreditorOrdersGrid.SelectedItem as CreditorOrderClient);
                        }
                    }
                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgCreditorOrdersGrid);
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
예제 #10
0
        async private void ShowProformaInvoice(CreditorOrderClient crOrder, IEnumerable <DCOrderLineClient> orderLines)
        {
            var invoicePostingResult = SetupInvoicePostingPrintGenerator(crOrder, orderLines, DateTime.Now, null, true, true, false, false, 0, false, false, false, null, null);

            busyIndicator.IsBusy      = true;
            busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
            var result = await invoicePostingResult.Execute();

            busyIndicator.IsBusy = false;

            if (!result)
            {
                Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgCreditorOrderLineGrid);
            }
        }
예제 #11
0
        void UpdateVoucher(VouchersClient attachedVoucher, CreditorOrderClient editrow)
        {
            if (attachedVoucher == null)
            {
                return;
            }
            var buf = attachedVoucher._Data;

            attachedVoucher._Data = null;
            var org = StreamingManager.Clone(attachedVoucher);

            attachedVoucher._Content         = ContentTypes.PurchaseInvoice;
            attachedVoucher._PurchaseNumber  = editrow._OrderNumber;
            attachedVoucher._CreditorAccount = editrow._InvoiceAccount ?? editrow._DCAccount;
            api.UpdateNoResponse(org, attachedVoucher);
            attachedVoucher._Data = buf;
        }
        private void JoinToSelectedItem(CreditorOrderClient selectedItem)
        {
            var    ordersToBeJoined = dgJoinMultiPurchaseGrid.GetVisibleRows() as IEnumerable <CreditorOrderClient>;
            var    acc  = selectedItem._DCAccount;
            string acc2 = null;

            foreach (var rec in ordersToBeJoined)
            {
                if (rec._DCAccount != acc)
                {
                    acc2 = rec._DCAccount;
                    break;
                }
            }
            if (acc2 != null)
            {
                string msg = string.Format("{0}\r\n{1}", string.Format(Uniconta.ClientTools.Localization.lookup("DifferentAccountMessage"), acc, acc2),
                                           Uniconta.ClientTools.Localization.lookup("AreYouSureToContinue"));
                var confirmationDialog = new CWConfirmationBox(msg, Uniconta.ClientTools.Localization.lookup("Confirmation"), false);
                confirmationDialog.Closing += delegate
                {
                    if (confirmationDialog.ConfirmationResult == CWConfirmationBox.ConfirmationResultEnum.Yes)
                    {
                        EraseYearWindow EraseYearWindowDialog = new EraseYearWindow("", true);
                        EraseYearWindowDialog.Closed += delegate
                        {
                            if (EraseYearWindowDialog.DialogResult == true)
                            {
                                JoinAllOrdersToSelectedItem(selectedItem, ordersToBeJoined);
                            }
                        };
                        EraseYearWindowDialog.Show();
                    }
                };
                confirmationDialog.Show();
            }
            else
            {
                JoinAllOrdersToSelectedItem(selectedItem, ordersToBeJoined);
            }
        }
예제 #13
0
        private void GenerateInvoice(CreditorOrderClient dbOrder, bool showProformaInvoice)
        {
            var lines = (IEnumerable <DCOrderLineClient>)dgCreditorOrderLineGrid.ItemsSource;

            if (lines == null || lines.Count() == 0)
            {
                return;
            }
            var dc = dbOrder.Creditor;

            if (dc == null || !Utility.IsExecuteWithBlockedAccount(dc))
            {
                return;
            }
            if (!api.CompanyEntity.SameCurrency(dbOrder._Currency, dc._Currency))
            {
                var confirmationMsgBox = UnicontaMessageBox.Show(string.Format("{0}.\n{1}", string.Format(Uniconta.ClientTools.Localization.lookup("CurrencyMismatch"), dc.Currency, dbOrder.Currency),
                                                                               Uniconta.ClientTools.Localization.lookup("ProceedConfirmation")), Uniconta.ClientTools.Localization.lookup("Confirmation"), MessageBoxButton.OKCancel);
                if (confirmationMsgBox != MessageBoxResult.OK)
                {
                    return;
                }
            }

            if (api.CompanyEntity._InvoiceUseQtyNowCre)
            {
                foreach (var rec in lines)
                {
                    rec._QtyNow = rec._Qty;
                }
            }

            if (showProformaInvoice)
            {
                ShowProformaInvoice(dbOrder, lines);
                return;
            }

            CWGenerateInvoice GenrateInvoiceDialog = new CWGenerateInvoice(true, string.Empty, true, true, showNoEmailMsg: !hasEmail);

#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000004;
#endif
            GenrateInvoiceDialog.SetInvoiceNumber(dbOrder._InvoiceNumber);
            if (dbOrder._InvoiceDate != DateTime.MinValue)
            {
                GenrateInvoiceDialog.SetInvoiceDate(dbOrder._InvoiceDate);
            }
            GenrateInvoiceDialog.SetInvPrintPreview(showInvoice);
            GenrateInvoiceDialog.SetSendAsEmailCheck(false);
            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    var isSimulated = GenrateInvoiceDialog.IsSimulation;
                    showInvoice = GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint || GenrateInvoiceDialog.SendByOutlook;
                    if (!isSimulated && GenrateInvoiceDialog.InvoiceNumber == null)
                    {
                        UtilDisplay.ShowErrorCode(ErrorCodes.InvoiceNumberMissing);
                        return;
                    }

                    var invoicePostingResult = SetupInvoicePostingPrintGenerator(dbOrder, lines, GenrateInvoiceDialog.GenrateDate, GenrateInvoiceDialog.InvoiceNumber, isSimulated, GenrateInvoiceDialog.ShowInvoice,
                                                                                 GenrateInvoiceDialog.PostOnlyDelivered, GenrateInvoiceDialog.InvoiceQuickPrint, GenrateInvoiceDialog.NumberOfPages, GenrateInvoiceDialog.SendByEmail, !isSimulated && GenrateInvoiceDialog.SendByOutlook,
                                                                                 GenrateInvoiceDialog.sendOnlyToThisEmail, GenrateInvoiceDialog.Emails, documents);

                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        if (!isSimulated)
                        {
                            dgCreditorOrderLineGrid.ItemsSource = new List <CreditorOrderLineClient>();
                            documents = null;
                            if (attachDocMenu != null)
                            {
                                attachDocMenu.Caption = string.Format(Uniconta.ClientTools.Localization.lookup("AttachOBJ"), Uniconta.ClientTools.Localization.lookup("Documents"));
                            }
                        }

                        if (invoicePostingResult.IsInvoiceGenerated)
                        {
                            if (attachedVoucher != null)
                            {
                                attachedVoucher.PurchaseNumber = Order._OrderNumber;
                                api.UpdateNoResponse(attachedVoucher);
                            }
                            ClearFields(initialOrder);
                        }
                    }
                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgCreditorOrderLineGrid);
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
 /// <summary>
 /// Intialization of CreditorInvoice with Creditor Order
 /// </summary>
 /// <param name="postingResult">Invoice posting result</param>
 /// <param name="api">Api instance</param>
 /// <param name="companyLayoutType">Layout type</param>
 /// <param name="orderClient">Creditor Order client instance</param>
 public CreditorPrintReport(InvoicePostingResult postingResult, CrudAPI api, CompanyLayoutType companyLayoutType, CreditorOrderClient orderClient) : this(postingResult, api, companyLayoutType)
 {
     CreditorOrder = orderClient;
 }
예제 #15
0
        public void InsertKøbsfakturaer()
        {
            int?lastFakid = null;
            CreditorOrderClient recOrder = null;

            var rec_regnskab = Program.qryAktivRegnskab();
            var qryKFak      = from kfv in Program.karFakturavarer_k
                               join kf in Program.karFakturaer_k on new { fakid = kfv.Fakid } equals new { fakid = kf.fakid }
            where kf.faknr != 0 && kf.faktype == 2
            orderby kfv.Fakid, kfv.Line
                select new
            {
                Regnskabid  = rec_regnskab.Rid,
                Sk          = "K",
                Fakid       = kfv.Fakid,
                Faknr       = kf.faknr,
                Dato        = kf.dato,
                kreditornr  = kf.kreditornr,
                Faklinnr    = kfv.Line,
                Varenr      = kfv.Varenr,
                Tekst       = kfv.VareTekst,
                Konto       = kfv.Bogfkonto,
                Momskode    = KarKontoplan.getMomskode(kfv.Bogfkonto),
                Antal       = kfv.Antal,
                Enhed       = kfv.Enhed,
                Pris        = kfv.Pris,
                Rabat       = kfv.Rabat,
                Moms        = kfv.Moms,
                Nettobelob  = kfv.Nettobelob,
                Bruttobelob = kfv.Bruttobelob,
            };

            int antal = qryKFak.Count();

            var api = UCInitializer.GetBaseAPI;

            //var col3 = await api.Query<CreditorOrderClient>();
            //var col4 = await api.Query<CreditorOrderLineClient>();

            foreach (var k in qryKFak)
            {
                if ((!(k.Fakid == 0)) && (lastFakid != k.Fakid))
                {
                    try
                    {
                        var crit = new List <PropValuePair>();
                        var pair = PropValuePair.GenereteWhereElements("OrderNumber", typeof(int), k.Fakid.ToString());
                        crit.Add(pair);
                        var taskCreditorOrder = api.Query <CreditorOrderClient>(null, crit);
                        taskCreditorOrder.Wait();
                        var col = taskCreditorOrder.Result;
                        if (col.Count() == 0)
                        {
                            recOrder = new CreditorOrderClient()
                            {
                                OrderNumber  = k.Fakid,
                                Account      = k.kreditornr.ToString(),
                                InvoiceDate  = k.Dato,
                                DeliveryDate = k.Dato,
                            };
                            var taskInsertCreditorOrder = api.Insert(recOrder);
                            taskInsertCreditorOrder.Wait();
                            var err = taskInsertCreditorOrder.Result;
                        }
                        else
                        {
                            recOrder = col[0];
                        }
                    }
                    catch { }
                }

                CreditorOrderLineClient recOrderLine = new CreditorOrderLineClient()
                {
                    Text           = k.Tekst,
                    Qty            = (double)k.Antal,
                    Price          = (double)k.Pris,
                    PostingAccount = KarNyKontoplan.NytKontonr(k.Konto)
                };
                recOrderLine.SetMaster(recOrder);
                var taskInsertCreditorOrderLine = api.Insert(recOrderLine);
                taskInsertCreditorOrderLine.Wait();
                var err1 = taskInsertCreditorOrderLine.Result;
            }
        }
예제 #16
0
        private void OrderConfirmation(CreditorOrderClient dbOrder, CompanyLayoutType doctype)
        {
            InvoiceAPI Invapi         = new InvoiceAPI(api);
            var        creditor       = dbOrder.Creditor;
            bool       showSendByMail = true;

            if (creditor != null)
            {
                showSendByMail = !string.IsNullOrEmpty(creditor._InvoiceEmail);
            }
            string            creditorName       = creditor?._Name ?? dbOrder._DCAccount;
            var               comp               = api.CompanyEntity;
            bool              showUpdateInv      = comp.Storage || (doctype == CompanyLayoutType.PurchasePacknote && comp.CreditorPacknote);
            CWGenerateInvoice GenrateOfferDialog = new CWGenerateInvoice(false, doctype.ToString(), showInputforInvNumber: doctype == CompanyLayoutType.PurchasePacknote ? true : false,
                                                                         isShowInvoiceVisible: true, askForEmail: true, showNoEmailMsg: !showSendByMail, debtorName: creditorName, isShowUpdateInv: showUpdateInv);

#if !SILVERLIGHT
            switch (doctype)
            {
            case CompanyLayoutType.PurchaseOrder:
                GenrateOfferDialog.DialogTableId = 2000000003;
                break;

            case CompanyLayoutType.PurchasePacknote:
                GenrateOfferDialog.DialogTableId = 2000000056;
                break;

            case CompanyLayoutType.Requisition:
                GenrateOfferDialog.DialogTableId = 2000000057;
                break;
            }
#endif
            GenrateOfferDialog.SetInvPrintPreview(showInvPrintPreview);
            var additionalOrdersList = Utility.GetAdditionalOrders(api, dbOrder);
            if (additionalOrdersList != null)
            {
                GenrateOfferDialog.SetAdditionalOrders(additionalOrdersList);
            }
            GenrateOfferDialog.Closed += async delegate
            {
                if (GenrateOfferDialog.DialogResult == true)
                {
                    showInvPrintPreview = GenrateOfferDialog.ShowInvoice || GenrateOfferDialog.InvoiceQuickPrint || GenrateOfferDialog.SendByOutlook;
                    string documentNumber = null;
                    if (doctype == CompanyLayoutType.PurchasePacknote)
                    {
                        documentNumber         = GenrateOfferDialog.InvoiceNumber;
                        dbOrder._InvoiceNumber = documentNumber;
                    }
                    var openOutlook          = doctype == CompanyLayoutType.PurchasePacknote ? GenrateOfferDialog.UpdateInventory && GenrateOfferDialog.SendByOutlook : GenrateOfferDialog.SendByOutlook;
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this);
                    invoicePostingResult.SetUpInvoicePosting(dbOrder, null, doctype, GenrateOfferDialog.GenrateDate, documentNumber, !GenrateOfferDialog.UpdateInventory, GenrateOfferDialog.ShowInvoice, false,
                                                             GenrateOfferDialog.InvoiceQuickPrint, GenrateOfferDialog.NumberOfPages, GenrateOfferDialog.SendByEmail, openOutlook, GenrateOfferDialog.sendOnlyToThisEmail, GenrateOfferDialog.Emails,
                                                             false, null, false);
                    invoicePostingResult.SetAdditionalOrders(GenrateOfferDialog.AdditionalOrders?.Cast <DCOrder>().ToList());

                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        DebtorOrders.Updatedata(dbOrder, doctype);
                    }

                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgCreditorOrdersGrid);
                    }
                }
            };
            GenrateOfferDialog.Show();
        }